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;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<array<ll, 3>> pts;
int s = 0;
for (int i=0; i<n; i++) {
ll c, v, f; cin >> c >> f >> v;
pts.push_back({f, c, -v});
s += c;
}
int m; cin >> m;
for (int i=0; i<m; i++) {
ll c, v, f; cin >> c >> f >> v;
pts.push_back({f, c, v});
}
sort(pts.rbegin(), pts.rend());
vector<ll> dp(s+1, -1e18);
dp[0] = 0;
for (auto [f, c, v] : pts) {
// cout << f << ' ' << c << ' ' << v << endl;
if (v > 0) { // cust
for (int i=c; i<=s; i++) {
dp[i - c] = max(dp[i - c], dp[i] + v);
}
} else { // comp
for (int i=s-c; i>=0; i--) {
dp[i + c] = max(dp[i + c], dp[i] + v);
}
}
}
ll ans = 0;
for (ll x : dp) ans = max(ans, x);
cout << ans << endl;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:29:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | for (auto [f, c, v] : pts) {
| ^
# | 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... |