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 <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#define ll long long
#define INF 10e12
#define MINF -INF
#define N 2020
#define lli std::pair<long long,std::pair<long long,int>>
std::vector<lli> ord;
std::vector<lli> com;
ll dp[N][55];
int main(void){
int n,m;
scanf("%d",&n);
int c,f,v;
for(int i = 0;i<n;i++){
scanf("%d %d %d",&c,&f,&v);
com.push_back({(ll)f,{(ll)v,c}});
};
scanf("%d",&m);
for(int i = 0;i<m;i++){
scanf("%d %d %d",&c,&f,&v);
ord.push_back({(ll)f,{(ll)v,c}});
};
std::sort(com.begin(),com.end(),std::less<lli>());
std::sort(ord.begin(),ord.end(),std::less<lli>());
/*
for(auto i: com){
printf("%lld %lld %d\n",i.first,i.second.first,i.second.second);
};
puts("");
for(auto i: ord){
printf("%lld %lld %d\n",i.first,i.second.first,i.second.second);
};
puts("");
*/
for(int i = 0;i<N;i++){
for(int j = 0;j<55;j++){
dp[i][j] = MINF;
};
};
for(int j = 0;j<m;j++){
dp[j][0] = ord[j].second.first;
};
ll mx = 0;
for(int i = 0;i<n;i++){
for(int j = m-1;j>=0;j--){
int prevC = ord[j].second.second - com[i].second.second;
int prevM = j;
ll val = 0;
for(int k = ord[j].second.second;k>=0;k--){
if(com[i].first >= ord[j].first){
//printf("%d %d %d %lld %lld %lld %lld %d\n",i,j,k,dp[j][k],com[i].first,ord[j].first,ord[j].second.first,ord[j].second.second);
while(prevC < 0){
//printf("%d %d\n",prevC,prevM);
if(prevM == 0){
prevC = 0;
break;
};
val += ord[prevM].second.first;
prevM--;
prevC += ord[prevM].second.second;
};
if(dp[prevM][prevC] != MINF){
dp[j][k] = std::max(dp[prevM][prevC] + val - com[i].second.first, dp[j][k]);
if(k == ord[j].second.second){
mx = std::max(mx,dp[j][k]);
};
};
//printf("%d %d %d %lld %lld %lld %lld %d\n",i,j,k,dp[j][k],com[i].first,ord[j].first,ord[j].second.first,ord[j].second.second);
//printf("%lld %d %d\n",val,prevC,prevM);
//puts("");
if(prevC > 0 || prevM != 0){
prevC--;
};
};
};
};
};
printf("%lld\n",mx);
return 0;
};
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
clo.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&c,&f,&v);
~~~~~^~~~~~~~~~~~~~~~~~~~~
clo.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&m);
~~~~~^~~~~~~~~
clo.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&c,&f,&v);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |