Submission #601730

#TimeUsernameProblemLanguageResultExecution timeMemory
601730pakhomoveeCloud Computing (CEOI18_clo)C++17
54 / 100
1102 ms2212 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define int long long
const int inf = 1e18;
const int maxn = 200'001;
int dp[maxn];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<pair<int, int>, pair<int, int>>> vv;
    for (int i = 0; i < n; ++i) {
        int c, f, v;
        cin >> c >> f >> v;
        vv.push_back({ { f, c }, { v, 1 } });
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, f, v;
        cin >> c >> f >> v;
        vv.push_back({ { f, c }, { v, 2 } });
    }
    sort(vv.rbegin(), vv.rend());
    fill(dp, dp + maxn, -inf);
    dp[0] = 0;
    for (pair<pair<int, int>, pair<int, int>> x : vv) {
        auto [p, q] = x;
        auto [f, c] = p;
        auto [v, t] = q;
        if (t == 1) {
            for (int j = maxn - 1; j >= c; --j) {
                dp[j] = max(dp[j - c] - v, dp[j]);
            }
        } else {
            for (int j = 0; j + c < maxn; ++j) {
                dp[j] = max(dp[j], dp[j + c] + v);
            }
        }
    }
    cout << *max_element(dp, dp + maxn);
}
#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...