Submission #1270482

#TimeUsernameProblemLanguageResultExecution timeMemory
1270482osmiyumCloud Computing (CEOI18_clo)C++20
72 / 100
391 ms2040 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;
        // bilgisayar: çekirdek +c, değer -v
        all.push_back({c, -v, f});
    }

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

    // büyükten küçüğe clock'a göre sırala
    sort(all.begin(), all.end(), [](auto &a, auto &b){
        return a.f > b.f;
    });

    // toplam çekirdek sayısı üst sınır
    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) {
        vector<long long> ndp = dp;
        if (it.cores >= 0) {
            // bilgisayar ekliyor
            for (int j = 0; j <= MAXC - it.cores; j++) {
                if (dp[j] != NEG) {
                    ndp[j + it.cores] = max(ndp[j + it.cores], dp[j] + it.val);
                }
            }
        } else {
            int need = -it.cores;
            for (int j = need; j <= MAXC; j++) {
                if (dp[j] != NEG) {
                    ndp[j - need] = max(ndp[j - need], dp[j] + it.val);
                }
            }
        }
        dp.swap(ndp);
    }

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