이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |