# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84469 | hamzqq9 | Schools (IZhO13_school) | C++14 | 378 ms | 22660 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 st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2005000000
#define MOD 1000000007
#define N 300005
#define M 1000005
#define LOG 18
#define KOK 4000000
using namespace std;
int n,m,s;
ii a[N];
ll ans;
priority_queue<int> q;
multiset<ii> ma,mb;
int main() {
//freopen("input.txt","r",stdin);
scanf("%d %d %d",&n,&m,&s);
for(int i=1;i<=n;i++) {
scanf("%d %d",&a[i].st,&a[i].nd);
}
sort(a+1,a+1+n,[](ii x,ii y) {
if(x.st==y.st) return x.nd<y.nd;
return x.st>y.st;
});
for(int i=1;i<=m;i++) {
ans+=a[i].st;
q.push(a[i].nd-a[i].st);
}
for(int i=m+1;i<=n;i++) {
ma.insert(a[i]);
mb.insert({a[i].nd,a[i].st});
}
while(s--) {
int val=q.top();
ii adda=*ma.rbegin();
ii addb=*mb.rbegin();
if(val+adda.st>addb.st) {
ans+=val+adda.st;
q.pop();
q.push(adda.nd-adda.st);
ma.erase(prev(ma.end()));
mb.erase(mb.find({adda.nd,adda.st}));
}
else {
ans+=addb.st;
mb.erase(prev(mb.end()));
ma.erase(ma.find({addb.nd,addb.st}));
}
}
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |