제출 #480330

#제출 시각아이디문제언어결과실행 시간메모리
480330TadiornCloud Computing (CEOI18_clo)C++14
100 / 100
1853 ms3620 KiB
#include <bits/stdc++.h>
#define MAXN 2010
#define INF 1000000000000000000LL

using namespace std;

struct data
{
    long long c;
    long long f;
    long long v;
};

data a[2*MAXN];

bool cmp(data x, data y)
{
    if(x.f > y.f) return true;
    else if(x.f < y.f) return false;
    else return x.c > y.c;
}

long long prevNiz[100*MAXN];
long long tr[100*MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    int n;
    cin >> n;
    int i = 0;
    long long C = 0;
    for(i = 0; i < n; i++)
    {
        cin >> a[i].c >> a[i].f >> a[i].v;
        C += a[i].c;
        a[i].v = -a[i].v;
    }
    int m;
    cin >> m;
    for(; i < n + m; i++)
    {
        cin >> a[i].c >> a[i].f >> a[i].v;
        C += a[i].c;
        a[i].c = -a[i].c;
    }
    for(int i = 0; i <= C; i++)
    {
        prevNiz[i] = -INF;
    }
    prevNiz[0] = 0;
    //cout << "CHECKPOINT 1" << endl;
    sort(a, a + m + n, cmp);
    for(int i = 0; i < n + m; i++)
    {
        //cout << "START" << endl;
        for(int j = 0; j <= C; j++)
        {
            //cout << "START 2" << endl;
            tr[j] = prevNiz[j];
            if(j - a[i].c >= 0 && j - a[i].c <= C && prevNiz[j - a[i].c] + a[i].v > tr[j] && prevNiz[j - a[i].c] != -INF)
            {
                tr[j] = prevNiz[j - a[i].c] + a[i].v;
            }
            //cout << "END 2" << endl;
        }
        //cout << "MID" << endl;
        for(int j = 0; j <= C; j++)
        {
            prevNiz[j] = tr[j];
        }
        //cout << "END" << endl;
    }
    //cout << "CHECKPOINT 2" << endl;

    long long  res = 0;
    for(int i = 0; i <= C; i++)
    {
        res = max(res, prevNiz[i]);
    }
    cout << res << endl;


    return 0;
}






























#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...