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;
void testCase() {
int n, m;
cin >> n;
vector<tuple<int, int, int>> t;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
t.push_back({f, c, -v});
}
cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
t.push_back({f, c, v});
}
sort(t.begin(), t.end(), [&](tuple<int, int, int> a, tuple<int, int, int> b) {
if (get<0> (a) != get<0> (b)) return get<0> (a) > get<0> (b);
return get<2> (a) < get<2> (b);
});
int s = n * 51;
vector<long long> dp(s, -1e18);
vector<long long> ndp;
dp[0] = 0;
for (auto [f, c, v] : t) {
ndp = dp;
if (v < 0) {
for (int i = 0; i + c < s; i++) {
if (dp[i] != -1e18) ndp[i + c] = max(ndp[i + c], dp[i] + v);
}
} else {
for (int i = c; i < s; i++) {
if (dp[i] != -1e18) ndp[i - c] = max(ndp[i - c], dp[i] + v);
}
}
dp = ndp;
}
cout << *max_element(dp.begin(), dp.end()) << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
# | 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... |