Submission #164500

#TimeUsernameProblemLanguageResultExecution timeMemory
164500itglSchools (IZhO13_school)C++14
5 / 100
391 ms10080 KiB
#include<bits/stdc++.h> #define ss second #define pb push_back #define mp make_pair #define ff first using namespace std; int n,m,s; vector<pair<int,int> > dp,dp1; int main(){ cin >> n >> m >> s; for(int i=1;i<=n;i++){ int x,y; cin >> x >> y; dp.pb(mp(x,i)); dp1.pb(mp(y,i)); } sort(dp.begin(),dp.end()); sort(dp1.begin(),dp1.end()); int res=0; for(int i=n-1;i>=0;i--){ if(m>0&&s>0){ if(dp[i].ss!=dp1[i].ss){ m--; s--; res+=dp[i].ff; res+=dp1[i].ff; } else{ if(dp[i-1].ff+dp1[i].ff>dp1[i-1].ff+dp[i].ff){ res+=dp[i-1].ff; res+=dp1[i].ff; i--; m--; s--; } else{ res+=dp1[i-1].ff; res+=dp[i].ff; i--; m--; s--; } } } if(m>0&&s==0){ res+=dp[i].ff; m--; } if(m==0&&s>0){ res+=dp1[i].ff; s--; } if(m<0&&s<0) break; } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...