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 i64 = long long;
constexpr int N = 100000;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 3>> a;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
a.push_back({c, f, -v});
}
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});
}
sort(a.begin(), a.end());
vector<i64> dp(N + 1, -1E15);
dp[0] = 0;
sort(a.begin(), a.end(), [&](const array<int, 3> &a, const array<int, 3> &b) {
if (a[1] == b[1])
return a[2] < b[2];
return a[1] > b[1];
});
for (auto [c, f, v] : a) {
if (v < 0) {
for (int i = N; i >= c; i--) {
dp[i] = max(dp[i], dp[i - c] + v);
}
} else {
for (int i = c; i <= N; i++) {
dp[i - c] = max(dp[i - c], dp[i] + v);
}
}
}
i64 ans = *max_element(dp.begin(), dp.end());
cout << ans << "\n";
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... |