# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
85825 | Vardanyan | Schools (IZhO13_school) | C++14 | 164 ms | 26208 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 "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 300*1000+5;
bool cmp(pair<int,int> x,pair<int,int> y){
return x.first-x.second>y.first-y.second;
}
long long A[N];
long long B[N];
int main(){
int n,m,s;
scanf("%d%d%d",&n,&m,&s);
vector<pair<int,int> > v;
for(int i = 1;i<=n;i++){
int ai,bi;
scanf("%d%d",&ai,&bi);
v.push_back({ai,bi});
}
sort(v.begin(),v.end(),cmp);
// for(int i = 0;i<v.size();i++) cout<<v[i].first<<" "<<v[i].second<<endl;
priority_queue<int> pq;
long long now = 0;
for(int i = 0;i<v.size();i++){
pq.push(-v[i].first);
now+=v[i].first;
if(pq.size()>m){
int x = -pq.top();
now-=x;
pq.pop();
}
A[i+1] = now;
}
while(pq.size()) pq.pop();
now = 0;
long long ans = 0;
for(int i = v.size()-1;i>=0;i--){
pq.push(-v[i].second);
now+=v[i].second;
if(pq.size()>s){
int x = -pq.top();
now-=x;
pq.pop();
}
B[i+1] = now;
}
for(int i = m;i<=n-s;i++) ans = max(ans,A[i]+B[i+1]);
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |