제출 #197511

#제출 시각아이디문제언어결과실행 시간메모리
197511handlenameCloud Computing (CEOI18_clo)C++17
100 / 100
396 ms1580 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...