#include<bits/stdc++.h>
#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;
int main(){
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
8 ms |
640 KB |
Output isn't correct |
8 |
Correct |
10 ms |
640 KB |
Output is correct |
9 |
Incorrect |
8 ms |
640 KB |
Output isn't correct |
10 |
Incorrect |
10 ms |
640 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
640 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
640 KB |
Output isn't correct |
13 |
Incorrect |
75 ms |
2936 KB |
Output isn't correct |
14 |
Incorrect |
149 ms |
6008 KB |
Output isn't correct |
15 |
Runtime error |
238 ms |
14328 KB |
Execution killed with signal 11 |
16 |
Runtime error |
240 ms |
14456 KB |
Execution killed with signal 11 |
17 |
Execution timed out |
2084 ms |
7928 KB |
Time limit exceeded |
18 |
Execution timed out |
2093 ms |
7928 KB |
Time limit exceeded |
19 |
Execution timed out |
2094 ms |
7928 KB |
Time limit exceeded |
20 |
Runtime error |
235 ms |
14456 KB |
Execution killed with signal 11 |