#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
const int N = 1e5+5;
int n, m, dp[N];
struct sct{
int id, c, f, v;
};
vector<sct> v;
bool cmp(sct a, sct b){
if(a.f == b.f) return a.id < b.id;
return a.f > b.f;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
int c, f, val;
cin >> c >> f >> val;
v.push_back({-1, c, f, val});
}
cin >> m;
for(int i = 1; i <= m; i++){
int c, f, val;
cin >> c >> f >> val;
v.push_back({1, c, f, val});
}
sort(v.begin(), v.end(), cmp);
for(int i = 1; i <= 100000; i++) dp[i] = -1e18;
for(auto [id, c, f, val] : v){
if(id == -1){
for(int i = 100000; i >= c; i--)
dp[i] = max(dp[i], dp[i - c] - val);
}
else{
for(int i = 0; i + c <= 100000; i++)
dp[i] = max(dp[i], dp[i + c] + val);
}
}
int ans = 0;
for(int i = 0; i <= 100000; i++)
ans = max(ans, dp[i]);
cout << ans;
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... |