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;
int n, m;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
vector<tuple<int, bool, int, int>> vt;
cin >> n;
for (int i = 1; i <= n; ++i) {
int c, f, p; cin >> c >> f >> p;
vt.emplace_back(f, true, c, p);
}
cin >> m;
for (int i = 1; i <= m; ++i) {
int c, f, p; cin >> c >> f >> p;
vt.emplace_back(f, false, c, p);
}
sort(vt.begin(), vt.end(), greater<>());
int MAX = 2000 * 50;
vector<long long> dp(MAX + 1, -1'000'000'000'000'000'000);
dp[0] = 0;
for (const auto& [f, t, c, p] : vt) {
if (t) for (int i = MAX; i >= c; --i) dp[i] = max(dp[i], dp[i - c] - p);
else for (int i = 0; i <= MAX - c; ++i) dp[i] = max(dp[i], dp[i + c] + p);
}
cout << *max_element(dp.begin(), dp.end()) << "\n";
}
# | 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... |