# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167005 | itgl | Schools (IZhO13_school) | C++14 | 2043 ms | 12356 KiB |
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>
#define ss second
#define pb push_back
#define mp make_pair
#define ff first
using namespace std;
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |