# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84398 | ekrem | Schools (IZhO13_school) | C++98 | 433 ms | 39740 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 mp make_pair
#define pb push_back
#define N 1000005
using namespace std;
typedef pair < int , int > ii;
int n, x, y;
long long ans;
ii a[N];
priority_queue < int > q;
multiset < ii > s, t;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d %d",&n ,&x ,&y);
for(int i = 1; i <= n; i++)
scanf("%d %d",&a[i].st ,&a[i].nd);
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
for(int i = 1; i <= x; i++){
ans += a[i].st;
q.push(a[i].nd - a[i].st);
}
// cout << ans << endl;
for(int i = x + 1; i <= n; i++){
s.insert(a[i]);
t.insert(mp(a[i].nd, a[i].st));
}
while(y--){
int frk = q.top();
ii son = *s.rbegin();
ii alma = *t.rbegin();
if(frk + son.st > alma.st){
ans += frk + son.st;
q.pop();
s.erase(s.find(son));
t.erase(t.find(mp(son.nd, son.st)));
q.push(son.nd - son.st);
} else{
ans += alma.st;
t.erase(t.find(alma));
s.erase(s.find(mp(alma.nd, alma.st)));
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |