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>
#define MAXN 2007
using namespace std;
struct item{
int c,f,v;
inline friend bool operator < (item fr,item sc){
return fr.f<sc.f;
}
}s[MAXN],t[MAXN];
int n,m;
long long dp[2][MAXN][107][2];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>s[i].c>>s[i].f>>s[i].v;
}
sort(s+1,s+n+1);
cin>>m;
for(int i=1;i<=m;i++){
cin>>t[i].c>>t[i].f>>t[i].v;
}
sort(t+1,t+m+1);
for(int i=0;i<=n;i++){
for(int f=0;f<=m;f++){
for(int c=0;c<=100;c++){
for(int e=0;e<2;e++){
dp[i%2][f][c][e]=0;
if(i==0 and f==0){
dp[i%2][f][c][e]=0; continue;
}
if(i>0)dp[i%2][f][c][e]=max(dp[i%2][f][c][e],dp[1-i%2][f][c][0]);
if(f>0)dp[i%2][f][c][e]=max(dp[i%2][f][c][e],dp[i%2][f-1][c][e]);
if(i>0 and c<50){
dp[i%2][f][c][e]=max(dp[i%2][f][c][e],dp[1-i%2][f][c+s[i].c][1]-s[i].v);
}
if(f>0 and c>=t[f].c and e==1 and t[f].f<=s[i+1].f){
dp[i%2][f][c][e]=max(dp[i%2][f][c][e],dp[i%2][f-1][c-t[f].c][e]+t[f].v);
}
}
}
}
}
cout<<dp[n%2][m][0][0]<<"\n";
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... |