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
vector <vector <int>> arr;
int n;
signed main () {
cin >> n;
for (int i = 0; i < n; i++) {
int a, b, c; cin >> a >> b >> c;
arr.push_back({a, b, -c});
}
cin >> n;
for (int i = 0; i < n; i++) {
int a, b, c; cin >> a >> b >> c;
arr.push_back({-a, b, c});
}
sort(arr.begin(), arr.end(), [] (vector <int> &a, vector <int> &b) {
if (a[1] == b[1]) return a[2] > b[2];
return a[1] < b[1];
});
n = arr.size();
int dp[50 * 5000 + 1];
for (int i = 0; i < 50 * 5000 + 1; i++) dp[i] = 0;
for (int i = 0; i < n; i++) {
vector <int> nn(50 * 5000 + 1);
for (int j = 0; j < 50 * 5000 + 1; j++) {
int sum = dp[j];
if (j + arr[i][0] >= 0) sum = max(sum, arr[i][2] + dp[j + arr[i][0]]);
nn[j] = sum;
}
for (int j = 0; j < 50 * 5000 + 1; j++) dp[j] = nn[j];
}
cout << dp[0] << '\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... |