# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714029 | Ahmed57 | Schools (IZhO13_school) | C++14 | 110 ms | 15860 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.
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int,int>a,pair<int,int>b){
return (a.first-a.second)>(b.first-b.second);
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,s,m;
cin>>n>>s>>m;
vector<pair<long long,long long>>v;
for(int i = 0;i<n;i++){
long long a,b;
cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end(),comp);
priority_queue<long long> p1,p2;
long long sum = 0,sum2 = 0;
long long pref[n+2] = {0},suf[n+2]= {0};
for(int i= 1;i<=n;i++){
p1.push(-v[i-1].first);
if(p1.size()>s){sum+=p1.top();p1.pop();}
sum+=v[i-1].first;
pref[i]=sum;
}
for(int i= n;i>=1;i--){
p2.push(-v[i-1].second);
if(p2.size()>m){sum2+=p2.top();p2.pop();}
sum2+=v[i-1].second;
suf[i]= sum2;
}
cout<<endl;
long long ans = -1e18;
for(int i = 0;i<=n;i++){
ans = max(ans,pref[i]+suf[i+1]);
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |