# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
972667 | imarn | Schools (IZhO13_school) | C++14 | 105 ms | 11468 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 f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define sz(x) (ll)x.size()
using namespace std;
bool cmp(pii a,pii b){
return a.f-a.s>b.f-b.s;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,s;cin>>n>>m>>s;pii a[n+1];
for(int i=1;i<=n;i++)cin>>a[i].f>>a[i].s;
sort(a+1,a+n+1,cmp);
ll dl[n+2]={0},dr[n+2]={0},sum=0;
priority_queue<int,vector<int>,greater<int>>q;
for(int i=1;i<=n;i++){
sum+=a[i].f;q.push(a[i].f);
while(!q.empty()&&q.size()>m)sum-=q.top(),q.pop();
dl[i]=sum;
}sum=0;while(!q.empty())q.pop();
for(int i=n;i>=1;i--){
sum+=a[i].s;q.push(a[i].s);
while(!q.empty()&&q.size()>s)sum-=q.top(),q.pop();
dr[i]=sum;
}ll ans=0;
for(int i=0;i<=n;i++)if(i>=m&&n-i>=s)ans=max(ans,dl[i]+dr[i+1]);
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |