# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30845 | Kerim | Schools (IZhO13_school) | C++14 | 316 ms | 14104 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 MAXN 300009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
PII arr[MAXN];
ll suf[MAXN];
multiset<int>st;
bool cmp(PII x,PII y){
return (x.ss-x.ff<y.ss-y.ff);
}
int main(){
//~ #ifndef ONLINE_JUDGE
//~ freopen("file.in", "r", stdin);
//~ #endif
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
scanf("%d%d",&arr[i].ff,&arr[i].ss);
sort(arr+1,arr+n+1,cmp);
ll cur=0;
for(int i=n;i>n-b;i--)
st.insert(arr[i].ss),cur+=arr[i].ss;
suf[n-b+1]=cur;
for(int i=n-b;i>a;i--){
if(*st.begin()<arr[i].ss){
cur-=*st.begin();cur+=arr[i].ss;
st.erase(st.begin());
st.insert(arr[i].ss);
}suf[i]=cur;
}st.clear();cur=0;
for(int i=1;i<=a;i++)
st.insert(arr[i].ff),cur+=arr[i].ff;
ll ans=cur+suf[a+1];
for(int i=a+1;i<=n-b;i++){
if(*st.begin()<arr[i].ff){
cur-=*st.begin();cur+=arr[i].ff;
st.erase(st.begin());
st.insert(arr[i].ff);
}
umax(ans,cur+suf[i+1]);
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |