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 sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 2000, C = 50;
const ll infL = 3e18;
ll dp[C * N + 1];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 4>> a;
for (int i = 0; i < n; ++i) {
int c, f, v;
cin >> c >> f >> v;
a.push_back({f, 1, c, v});
}
int m;
cin >> m;
int sum = N * C;
for (int i = 0; i < m; ++i) {
int c, f, v;
cin >> c >> f >> v;
a.push_back({f, 0, c, v});
}
sort(all(a));
for (auto [f, t, c, v] : a) {
if (t == 0) {
for (int k = sum; k >= c; --k) {
dp[k] = max(dp[k], dp[k - c] + v);
}
} else {
for (int k = c; k <= sum; ++k) {
dp[k - c] = max(dp[k - c], dp[k] - v);
}
}
for (int k = 1; k <= sum; ++k) {
dp[k] = max(dp[k], dp[k - 1]);
}
}
cout << dp[0];
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... |