Submission #804759

#TimeUsernameProblemLanguageResultExecution timeMemory
804759Valaki2Cloud Computing (CEOI18_clo)C++14
18 / 100
412 ms2020 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back

const int maxn = 2000;
const int maxc = 50;
const int inf = 1e16 + 42;

struct computer {
    int cores, freq, val;
    bool operator < (const computer & other) const {
        return freq < other.freq;
    }
};

int n, m;
vector<computer> computers, orders;
vector<int> dpmin, dpmax;

void solve() {
    cin >> n;
    computers.resize(1 + n);
    for(int i = 1; i <= n; i++) {
        cin >> computers[i].cores >> computers[i].freq >> computers[i].val;
    }
    sort(computers.begin() + 1, computers.end());
    cin >> m;
    orders.resize(1 + m);
    for(int i = 1; i <= m; i++) {
        cin >> orders[i].cores >> orders[i].freq >> orders[i].val;
    }
    sort(orders.begin() + 1, orders.end());
    dpmin.assign(1 + maxn * maxc, inf);
    dpmin[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = maxn * maxc; j >= computers[i].cores; j--) {
            dpmin[j] = min(dpmin[j], dpmin[j - computers[i].cores] + computers[i].val);
        }
    }
    for(int j = maxn * maxc - 1; j >= 0; j--) {
        dpmin[j] = min(dpmin[j], dpmin[j + 1]);
    }
    dpmax.assign(1 + maxn * maxc, -inf);
    dpmax[0] = 0;
    for(int i = 1; i <= m; i++) {
        for(int j = maxn * maxc; j >= orders[i].cores; j--) {
            dpmax[j] = max(dpmax[j], dpmax[j - orders[i].cores] + orders[i].val);
        }
    }
    int ans = 0;
    for(int i = 1; i <= maxn * maxc; i++) {
        ans = max(ans, dpmax[i] - dpmin[i]);
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    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...