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>
using namespace std;
struct thing{
int core,clock,price,type;
};
bool cmp(thing q,thing w ){
if(q.clock!=w.clock){
return q.clock<w.clock;
}
else{
return q.type>w.type;
}
}
int main(){
int n;
cin>>n;
thing barang[n+2];
vector<thing>tmp;
int sum=0;
for(int q=1;q<=n;q++){
cin>>barang[q-1].core>>barang[q-1].clock>>barang[q-1].price;
barang[q-1].type=0;
tmp.push_back(barang[q-1]);
sum+=barang[q-1].price;
}
int m;
cin>>m;
thing lain[m+2];
for(int q=1;q<=m;q++){
cin>>lain[q].core>>lain[q].clock>>lain[q].price;
lain[q].type=1;
tmp.push_back(lain[q]);
}
sort(tmp.begin(),tmp.end(),cmp);
long long dp[sum+2];
for(int w=0;w<=sum;w++){
dp[w]=-1e15;
}
dp[0]=0;
for(int q=n+m;q>=1;q--){
if(tmp[q-1].type==0){
for(int w=sum;w>=tmp[q-1].core;w--){
dp[w]=max(dp[w],dp[w-tmp[q-1].core]-tmp[q-1].price);
}
}
else{
for(int w=0;w+tmp[q-1].core<=sum;w++){
dp[w]=max(dp[w],dp[w+tmp[q-1].core]+tmp[q-1].price);
}
}
}
long long ans=0;
for(int q=0;q<=sum;q++){
ans=max(ans,dp[q]);
}
cout<<ans<<endl;
}
# | 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... |