#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,n1,n2,k,curAns,Cc,c,i,ans;
pair<int,int>p[N];
set<pair<int,int> > cur,cur2,s2;
main(){
ios_base::sync_with_stdio(false);
cin>>n>>n1>>n2;
for(k=1;k<=n;k++){
cin>>a[k]>>b[k];
p[k]={a[k]-b[k],k};
s2.insert({b[k],k});
}
sort(p+1,p+n+1);
reverse(p+1,p+n+1);
for(k=1;k<=n1;k++){
cur.insert({a[p[k].s],p[k].s});
curAns+=a[p[k].s];
s2.erase({b[p[k].s],p[k].s});
}
for(k=1;k<=n2;k++){
c=(*(--s2.end())).first;
i=(*(--s2.end())).second;
s2.erase({c,i});
cur2.insert({c,i});
curAns+=b[i];
}
//ans=curAns;
for(k=n1+1;k<=n-n2;k++){
c=(*cur.begin()).first;
i=(*cur.begin()).second;
if(c>a[p[k].second]) continue;
else {
int Cc=curAns;
Cc-=c; Cc+=a[p[k].second];
if(cur2.find({b[p[k].second],p[k].second})!=cur2.end()){
Cc-=b[p[k].second];
Cc+=(*(--s2.end())).first;
if(Cc>curAns){
cur2.erase({b[p[k].second],p[k].second});
cur2.insert(*(--s2.end()));
s2.erase(*(--s2.end()));
curAns=Cc;
}
}
else {
if(Cc>curAns){
curAns=Cc;
}
}
}
}
cout<<curAns<<endl;
}
Compilation message
school.cpp:10:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
768 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
768 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
768 KB |
Output isn't correct |
13 |
Incorrect |
41 ms |
3712 KB |
Output isn't correct |
14 |
Incorrect |
79 ms |
7800 KB |
Output isn't correct |
15 |
Runtime error |
157 ms |
19452 KB |
Execution killed with signal 11 |
16 |
Runtime error |
163 ms |
19448 KB |
Execution killed with signal 11 |
17 |
Execution timed out |
2083 ms |
9724 KB |
Time limit exceeded |
18 |
Execution timed out |
2067 ms |
9720 KB |
Time limit exceeded |
19 |
Execution timed out |
2086 ms |
9720 KB |
Time limit exceeded |
20 |
Runtime error |
151 ms |
19448 KB |
Execution killed with signal 11 |