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;
typedef long long ll;
const int MX = 4005, C = 50;
int N, M;
vector<array<int,3>> a;
ll dp[2][MX * C];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
for(int i = 0; i < MX * C; i++)
dp[0][i] = dp[1][i] = -1e18;
cin >> N;
for(int i = 1; i <= N; i++) {
int c, f, v;
cin >> c >> f >> v;
a.push_back({f, c, -v});
}
cin >> M;
for(int i = 1; i <= M; i++) {
int c, f, v;
cin >> c >> f >> v;
a.push_back({f, -c, v});
}
sort(a.rbegin(), a.rend());
dp[0][0] = 0;
for(int i = 0; i < N + M; i++) {
auto [f, c, v] = a[i];
int k = i & 1;
for(int j = 0; j < MX * C; j++) {
dp[k ^ 1][j] = dp[k][j];
if(j - c >= 0 && j - c < MX * C)
dp[k ^ 1][j] = max(dp[k ^ 1][j], dp[k][j - c] + v);
}
}
cout << *max_element(dp[(N + M) & 1], dp[(N + M) & 1] + C * MX) << '\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... |