제출 #133364

#제출 시각아이디문제언어결과실행 시간메모리
133364MinnakhmetovCloud Computing (CEOI18_clo)C++14
100 / 100
1488 ms2200 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2005, S = 1e5 + 5, K = 105;
const ll INF = 1e18;

struct C {
    int c, f, v;

    bool operator < (const C &oth) const {
        return f < oth.f;
    }
} a[N], b[N];

ll dp[N][K];

void upd(ll &a, ll b) {
    a = max(a, b);
}

signed main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i].c >> a[i].f >> a[i].v;
    }

    cin >> m;

    for (int i = 0; i < m; i++) {
        cin >> b[i].c >> b[i].f >> b[i].v;
    }

    sort(a, a + n);
    sort(b, b + m);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) {
            dp[i][j] = -INF;
        }
    }

    for (int i = 0; i < n; i++)
        dp[i][0] = 0;

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (b[i].f <= a[j].f) {
                for (int k = a[j].c - 1; k >= 0; k--) {
                    upd(dp[j][k + b[i].c], dp[j][k] + b[i].v);
                }
            }
        }
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < K; k++) {
                upd(dp[j + 1][k], dp[j][k]);
                upd(dp[j + 1][max(0, k - a[j].c)], dp[j][k] - a[j].v);
            }
        }
    }

    cout << dp[n][0];

    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...