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;
struct pc {
int core;
int freq;
int value;
} pc1[2001], pc2[2001], a[4001];
bool csort(pc a, pc b) {
if (a.freq > b.freq)
return 1;
else if (a.freq == b.freq && a.core > b.core)
return 1;
return 0;
}
long long dp[2][50 * 4001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> pc1[i].core >> pc1[i].freq >> pc1[i].value;
a[i] = {pc1[i].core, pc1[i].freq, -pc1[i].value};
}
int m;
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> pc2[i].core >> pc2[i].freq >> pc2[i].value;
a[n + i] = {-pc2[i].core, pc2[i].freq, pc2[i].value};
}
int l = n + m;
sort(a + 1, a + l + 1, csort);
for (int i = 0; i <= 1; i++)
for (int j = 0; j <= l * 50; j++)
dp[i][j] = -1e18;
dp[0][0] = 0;
for (int i = 1; i <= l; i++) {
for (int j = 0; j <= l * 50; j++)
dp[i % 2][j] = dp[1 - i % 2][j];
for (int j = 0; j <= l * 50; j++)
if (j - a[i].core >= 0 && j - a[i].core <= l * 50)
dp[i % 2][j] = max(dp[i % 2][j], dp[1 - i % 2][j - a[i].core] + a[i].value);
}
long long Max = 0;
for (int i = 0; i <= l * 50; i++)
Max = max(Max, dp[l % 2][i]);
cout << Max << '\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... |