#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<array<int , 4>> e;
for(int i = 0;i < n;i ++){
int c , f , v;
cin >> c >> f >> v;
e.emplace_back(array<int , 4>{f , 1 , c , v});
}
int m;
cin >> m;
for(int i = 0;i < m;i ++){
int c , f , v;
cin >> c >> f >> v;
e.emplace_back(array<int , 4>{f , 0 , c , v});
}
sort(e.rbegin() , e.rend());
int L = n * 50;
vector<long long> dp(L + 1 , -1E18);
dp[0] = 0LL;
for(int i = 0;i < n + m;i ++){
if(e[i][1] > 0){
for(int j = L;j >= e[i][2];j --){
dp[j] = max(dp[j] , dp[j - e[i][2]] - e[i][3]);
}
}else{
for(int j = 0;j + e[i][2] <= L;j ++){
dp[j] = max(dp[j] , dp[j + e[i][2]] + e[i][3]);
}
}
}
cout << *max_element(dp.begin() , dp.end()) << '\n';
}
/*
4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550
*/
# | 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... |