이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |