# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672948 | Baytoro | Schools (IZhO13_school) | C++17 | 119 ms | 16656 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>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18;
struct node{
int a,b,d;
};
bool cmp(node a, node b){
return a.d>b.d;
}
int n,m,s;
void solve(){
cin>>n>>m>>s;
vector<node> vec(n);
for(int i=0;i<n;i++){
cin>>vec[i].a>>vec[i].b;
vec[i].d=vec[i].a-vec[i].b;
}
sort(all(vec),cmp);
int sum=0;
vector<int> pref(n+1),suf(n+1);
priority_queue<int,vector<int>,greater<int>> dq;
for(int i=0;i<n;i++){
int x=vec[i].a;
dq.push(x);
sum+=x;
if((int)dq.size()>m){
sum-=dq.top();
dq.pop();
}
pref[i]=sum;
}
while(!dq.empty()) dq.pop();
sum=0;
for(int i=n-1;i>=0;i--){
int x=vec[i].b;
dq.push(x);
sum+=x;
if((int)dq.size()>s){
sum-=dq.top();
dq.pop();
}
suf[i]=sum;
}
int ans=0;
for(int i=0;i<n;i++)
ans=max(ans,pref[i]+suf[i+1]);
cout<<ans;
}
main(){
//fopn("262144");
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |