#include <bits/stdc++.h>
#define int long long
#define sc second
#define fr first
using namespace std;
pair <int, pair<int, int> > ar[100001];
int pr[100002], sf[100002];
multiset <int> st1, st2;
main()
{
int n,a,b;
cin>>n>>a>>b;
for(int i=0;i<n;i++){
cin>>ar[i].sc.fr>>ar[i].sc.sc;
ar[i].fr=ar[i].sc.sc - ar[i].sc.fr;
}
sort(ar,ar+n);
int sum=0;
for(int i=0;i<n;i++){
if(i<a){
sum+=ar[i].sc.fr;
pr[i]=sum;
st1.insert(ar[i].sc.fr);
}
else{
sum+=ar[i].sc.fr;
st1.insert(ar[i].sc.fr);
sum-=(*st1.begin());
pr[i]=sum;
st1.erase(*st1.begin());
}
}
sum=0;
for(int i=n-1;i>=0;i--){
if(n-b <= i){
sum+=ar[i].sc.sc;
sf[i]=sum;
st2.insert(ar[i].sc.sc);
}
else{
sum+=ar[i].sc.sc;
st2.insert(ar[i].sc.sc);
sum-=(*st2.begin());
sf[i]=sum;
st2.erase(*st2.begin());
}
}
int mx=0;
for(int i= max(0LL,a-1);i<n-b;i++)
mx=max(pr[i] + sf[i+1],mx);
if(a==0)
mx=max(sf[0],mx);
cout<<mx<<endl;
}
Compilation message
school.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Incorrect |
2 ms |
536 KB |
Output isn't correct |
5 |
Correct |
2 ms |
580 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Incorrect |
5 ms |
860 KB |
Output isn't correct |
8 |
Correct |
6 ms |
1040 KB |
Output is correct |
9 |
Incorrect |
6 ms |
1156 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
1156 KB |
Output isn't correct |
11 |
Incorrect |
6 ms |
1200 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
1256 KB |
Output isn't correct |
13 |
Incorrect |
37 ms |
3820 KB |
Output isn't correct |
14 |
Incorrect |
73 ms |
5384 KB |
Output isn't correct |
15 |
Runtime error |
60 ms |
5692 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
59 ms |
5792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
63 ms |
5792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Runtime error |
62 ms |
5792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Runtime error |
63 ms |
5844 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
62 ms |
5908 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |