# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90931 | kylych03 | Schools (IZhO13_school) | C++14 | 380 ms | 27352 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 int long long
#define sc second
#define fr first
#define mp make_pair
using namespace std;
pair <int, pair<int, int> > ar[300001];
int pr[300002], sf[300002];
multiset < pair <int,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(mp(ar[i].sc.fr, i ) );
}
else{
sum+=ar[i].sc.fr;
st1.insert(mp(ar[i].sc.fr, i ) );
sum-=(st1.begin()->first);
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(mp(ar[i].sc.sc,i));
}
else{
sum+=ar[i].sc.sc;
st2.insert(mp(ar[i].sc.sc,i));
sum-=(st2.begin()->first);
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |