Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.3 kB
3
Indexable
Never
---------------MAIN------------------------

#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <string.h>

struct Result
{
	int mPrice;
	int mPerformance;
};

extern void init(int mCharge);
extern Result order(int mBudget);
extern int stock(int mType, int mPerformance, int mPrice, int mPosition);

/////////////////////////////////////////////////////////////////////////

#define INIT	0
#define STOCK	1
#define ORDER	2

static bool run()
{
	int cmd, ans, ans2, ret;
	int in, in2, in3, in4;
	int Q = 0;
	bool okay = false;
	Result Ret;

	scanf("%d", &Q);

	for (int q = 0; q < Q; ++q)
	{
		scanf("%d", &cmd);

		switch (cmd)
		{
		case INIT:
			scanf("%d", &in);
			init(in);
			okay = true;
			break;

		case STOCK:
			scanf("%d %d %d %d", &in, &in2, &in3, &in4);
			ret = stock(in, in2, in3, in4);
			scanf("%d", &ans);
			if (ret != ans)
				okay = false;
			break;

		case ORDER:
			scanf("%d", &in);
			Ret = order(in);
			scanf("%d %d", &ans, &ans2);
			if (Ret.mPrice != ans || Ret.mPerformance != ans2)
				okay = false;
			break;

		default:
			okay = false;
		}
	}

	return okay;
}
int main()
{
	setbuf(stdout, NULL);
	// freopen("sample_input.txt", "r", stdin);

	int T, MARK;
	scanf("%d %d", &T, &MARK);

	for (int tc = 1; tc <= T; tc++)
	{
		int score = run() ? MARK : 0;
		printf("#%d %d\n", tc, score);
	}

	return 0;
}


---------------USER------------------------

#define MAX_STOCK 4007
#define min(a, b) ((a < b) ? (a) : (b))
 
int Charge;
 
struct Result
{
    int mPrice;
    int mPerformance;
};
 
struct Node {
    int price, per;
} Pool[MAX_STOCK];
int idPool;
 
int stocks[2][3][MAX_STOCK];
int cnt[2][3];
 
void init(int mCharge)
{
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 3; j++)
            cnt[i][j] = 0;
    Charge = mCharge;
    idPool = 1;
}
 
int stock(int mType, int mPrice, int mPerformance, int mPosition)
{
    Pool[idPool].price = mPrice;
    Pool[idPool].per = mPerformance;
    stocks[mPosition][mType][cnt[mPosition][mType]++] = idPool++;
    return cnt[mPosition][mType];
}
 
Result order(int mBudget)
{
    Result res = { 0, 0 };
    int l = 0, h = 1000000;
    int Rprice = 0;
 
    while (l < h-1)
    {
        int p1[2][3];
        int p2[3];
        int mid = (l + h)/2;
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                int Min = 1000000;
                for (int m = 0; m < cnt[i][j]; m++) {
                    int id = stocks[i][j][m];
                    if (Pool[id].per >= mid && Pool[id].price < Min)
                        Min = Pool[id].price;
                }
                p1[i][j] = Min;
            }
        }
 
        for (int i = 0; i < 3; i++)
            p2[i] = min(p1[0][i], p1[1][i]);
 
        int price = min(min(p1[0][0] + p1[0][1] + p1[0][2],  p1[1][0] + p1[1][1] + p1[1][2]), p2[0] + p2[1] + p2[2]+Charge);
 
        if (price <= mBudget)
        {
            l = mid;
            Rprice = price;
        } else
            h = mid;
    }
    res.mPrice = Rprice;
    res.mPerformance = l;
    return res;
}