# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112906 | 0pt1mus23 | Schools (IZhO13_school) | C++14 | 82 ms | 14464 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 int long long int
#define ins insert
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 2e5 +23, inf = LLONG_MAX, LG = 20;
void fast(){
int n,m,s;
cin>>n>>m>>s;
vector<pii> arr(n+1);
for(int i =1;i<=n;i++){
cin>>arr[i].first>>arr[i].second;
}
sort(arr.begin()+1,arr.end(),[&](pii a,pii b){
return a.second - a.first < b.second - b.first;
});
vector<int> pref(n+10,0),suff(n+10,0);
int ans=0,pf=0;
priority_queue<int,vector<int>,greater<int>> q;
for(int i =1;i<=n;i++){
pf+=arr[i].first;
q.push(arr[i].first);
if(q.size()>m){
pf-=q.top();
q.pop();
}
pref[i]=pf;
}
while(!q.empty()) q.pop();
int sfa =0;
for(int i = n;i>=1;i--){
sfa+=arr[i].second;
q.push(arr[i].second);
if(q.size()>s){
sfa-=q.top();
q.pop();
}
suff[i]=sfa;
}
for(int i=1;i<=n;i++){
ans=max(ans,pref[i]+suff[i+1]);
}
putr(ans);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
fast();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |