#include <bits/stdc++.h>
using namespace std;
// #define double long double
#define int long long
#define pb push_back
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define MAX 200005
#define f first
#define s second
const int INF = 1e18;
#define pii pair<int,int>
bool cmp(array<int,3>&a,array<int,3>&b){
if(a[1]!=b[1]) return a[1]>b[1];
return a[2]<b[2];
}
void solve(){
int n; cin>>n;
vector<array<int,3>> arr; arr.pb({INF,INF,INF});
for(int i=1;i<=n;i++){
int a,b,c; cin>>a>>b>>c; arr.pb({a,b,-c});
}
int m; cin>>m;
for(int i=1;i<=m;i++){
int a,b,c; cin>>a>>b>>c; arr.pb({-a,b,c});
}
sort(arr.begin(),arr.end(),cmp);
vi dp(1e5+5,-INF),ndp(1e5+5,-INF); dp[0]=0;
for(int i=1;i<arr.size();i++){
for(int j=0;j<=1e5;j++){
ndp[j]=dp[j];
if(j-arr[i][0]>=0 && j-arr[i][0]<=1e5) ndp[j]=max(ndp[j], dp[j-arr[i][0]]+arr[i][2] );
}
swap(dp,ndp);
}
int ans=0;
for(int i=0;i<=1e5;i++) ans=max(ans,dp[i]);
cout<<ans<<endl;
}
int32_t main(){
// freopen("talent.in","r",stdin);
// freopen("talent.out","w",stdout);
int t=1;
// cin>>t;
while(t--) solve();
}
| # | 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... |