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<bits/stdc++.h>
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n;
vector<array<int, 4>> a;
int sumc = 0;
for (int i = 0; i < n; ++i) {
int c, f, v; cin >> c >> f >> v;
a.push_back({c, f, -v, 0});
sumc += c;
}
int m; cin >> m;
for (int i = 0; i < m; ++i) {
int c, f, v; cin >> c >> f >> v;
a.push_back({-c, f, v, 1});
}
sort(a.begin(), a.end(), [](array<int, 4> x, array<int, 4> y) {
if (x[1] != y[1]) return x[1] > y[1];
return x[2] < y[2];
});
const long long INF = 2e18;
vector<long long> dp(sumc + 1, -INF);
dp[0] = 0;
for (auto [c, f, v, ignored]: a) {
vector<long long> cur = dp;
for (int w = 0; w <= sumc; ++w) {
int req = w - c;
if (req < 0 || req > sumc) continue;
if (dp[req] == -INF) continue;
cur[w] = max(cur[w], dp[req] + v);
}
swap(dp, cur);
}
cout << *max_element(dp.begin(), dp.end());
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:30:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for (auto [c, f, v, ignored]: a) {
| ^
# | 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... |