This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
vector<tuple<ll, ll, ll>> actions;
ll nCores = 0;
for (ll i = 0; i < n; i++) {
ll c, f, v;
cin >> c >> f >> v;
actions.push_back(make_tuple(f, c, -v));
nCores += c;
}
ll m;
cin >> m;
for (ll i = 0; i < m; i++) {
ll c, f, v;
cin >> c >> f >> v;
actions.push_back(make_tuple(f, -c, v));
}
sort(actions.begin(), actions.end(), greater<tuple<ll, ll, ll>>());
vector<ll> profits(nCores + 1, -4e18);
profits[0] = 0;
for (auto d : actions) {
ll f, v, c;
tie(f, c, v) = d;
vector<ll> cur = profits;
for (ll i = 0; i <= nCores; i++) {
if (i - c < 0 or i - c > nCores) {
continue;
}
cur[i] = max(cur[i], profits[i - c] + v);
}
profits = cur;
}
ll ans = 0;
for (ll c : profits) {
ans = max(ans, c);
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |