Submission #1270483

#TimeUsernameProblemLanguageResultExecution timeMemory
1270483osmiyumCloud Computing (CEOI18_clo)C++20
72 / 100
292 ms1096 KiB
#include <bits/stdc++.h>
using namespace std;

struct Item {
    int cores;
    long long val;
    long long f;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector<Item> all;

    for (int i = 0; i < n; i++) {
        int c; long long f, v;
        cin >> c >> f >> v;
        all.push_back({c, -v, f}); // bilgisayar
    }

    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        int C; long long F, V;
        cin >> C >> F >> V;
        all.push_back({-C, V, F}); // müşteri
    }

    sort(all.begin(), all.end(), [](auto &a, auto &b){
        return a.f > b.f;
    });

    int MAXC = 0;
    for (auto &it : all) if (it.cores > 0) MAXC += it.cores;

    const long long NEG = -4e18;
    vector<long long> dp(MAXC+1, NEG);
    dp[0] = 0;

    for (auto &it : all) {
        if (it.cores >= 0) {
            // bilgisayar ekliyor → sağdan sola
            for (int j = MAXC - it.cores; j >= 0; j--) {
                if (dp[j] != NEG) {
                    dp[j + it.cores] = max(dp[j + it.cores], dp[j] + it.val);
                }
            }
        } else {
            int need = -it.cores;
            // müşteri → soldan sağa
            for (int j = need; j <= MAXC; j++) {
                if (dp[j] != NEG) {
                    dp[j - need] = max(dp[j - need], dp[j] + it.val);
                }
            }
        }
    }

    long long ans = 0;
    for (long long v : dp) ans = max(ans, v);
    cout << ans << "\n";
}
#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...