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;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b ? (a = b) == b : false;
}
const int inf = 1e18;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n;
vector<array<int, 4>> vec;
for (int i = 0; i < n; ++i) {
int c, f, v; cin >> c >> f >> v;
vec.push_back({f, 1, v, c});
}
int m; cin >> m;
for (int i = 0; i < m; ++i) {
int c, f, v; cin >> c >> f >> v;
vec.push_back({f, 0, v, c});
}
sort(all(vec));
vector<int> dp(50 * n + 1, -inf);
dp[0] = 0;
while (!vec.empty()) {
auto [C, V] = make_pair(vec.back()[3], vec.back()[2]);
if (vec.back()[1]) {
for (int i = 50 * n - C; i >= 0; --i) {
chmax(dp[i + C], dp[i] - V);
}
} else {
for (int i = C; i <= 50 * n; ++i) {
chmax(dp[i - C], dp[i] + V);
}
}
vec.pop_back();
}
cout << *max_element(all(dp));
}
# | 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... |