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;
const int k_N = 2000 + 3;
const int k_C = 50;
int n, m;
array<int, 4> arr[2 * k_N];//f, which, c, v
long long dp[2][k_N * k_C];
int sum_c;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> arr[i][2] >> arr[i][0] >> arr[i][3];
arr[i][1] = 1;
sum_c += arr[i][2];
}
cin >> m;
for(int i = 0; i < m; ++i){
cin >> arr[i + n][2] >> arr[i + n][0] >> arr[i + n][3];
arr[i + n][1] = 0;
}
sort(arr, arr + n + m);
reverse(arr, arr + n + m);
for(int i = 0; i <= sum_c; ++i)
dp[(n + m) & 1][i] = 0;
for(int i = n + m - 1; i >= 0; --i){
bool curr = i & 1;
bool nxt = !curr;
for(int j = 0; j <= sum_c; ++j){
long long &answer = dp[curr][j];
answer = dp[nxt][j];
if(arr[i][1])
answer = max(dp[nxt][j + arr[i][2]] - arr[i][3], answer);
else if(j >= arr[i][2])
answer = max(dp[nxt][j - arr[i][2]] + arr[i][3], answer);
}
}
cout << dp[0][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... |