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;
int n,m,c,f,v;
long long dp[100001],ans;
vector<pair<pair<int,bool>,pair<int,int> > > arr;
bool cussort(pair<pair<int,bool>,pair<int,int> >a,pair<pair<int,bool>,pair<int,int> > b){
if (a.first.first==b.first.first) return a.first.second>b.first.second;
return a.first.first>b.first.first;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for (int i=0;i<n;i++){
cin>>c>>f>>v;
arr.push_back(make_pair(make_pair(f,true),make_pair(c,v)));
}
cin>>m;
for (int i=0;i<m;i++){
cin>>c>>f>>v;
arr.push_back(make_pair(make_pair(f,false),make_pair(c,v)));
}
sort(arr.begin(),arr.end(),cussort);
for (int i=1;i<100001;i++) dp[i]=-2e12;
for (auto cur:arr){
int c=cur.second.first;
int v=cur.second.second;
if (cur.first.second){
for (int i=100000;i>=c;i--){
dp[i]=max(dp[i],dp[i-c]-v);
}
}
else {
for (int i=0;i<100001-c;i++){
dp[i]=max(dp[i],dp[i+c]+v);
}
}
}
for (int i=0;i<100001;i++) ans=max(ans,dp[i]);
cout<<ans;
}
# | 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... |