# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167006 | 2019-12-05T07:54:04 Z | itgl | Schools (IZhO13_school) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> #define ss second #define pb push_back #define mp make_pair #define ff first using namespace std; freopen(school.in,"r",stdin); freopen(school.out,"w",strout); int n,m,s; priority_queue<pair<int,int> > pq,pq1; int main(){ cin >> n >> m >> s; for(int i=1;i<=n;i++){ int x,y; cin >> x >> y; pq.push(mp(x,x-y)); } int res=0; while(!pq.empty()){ if(m>0){ if(pq.top().ss>0&&s<=0){ res+=pq.top().ff; pq.pop(); m--; }else if(s>0){ pq1.push(mp(pq.top().ff-pq.top().ss,-pq.top().ss)); pq.pop(); } } else{ pq1.push(mp(pq.top().ff-pq.top().ss,-pq.top().ss)); pq.pop(); } } while(!pq1.empty()){ if(s>0){ res+=pq1.top().ff; pq1.pop(); s--; } else { pq.push(mp(pq1.top().ff-pq1.top().ss,-pq.top().ss)); pq1.pop(); } } while(m--){ res+=pq.top().ff; pq.pop(); } cout << res; return 0; }