# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
343819 | nandonathaniel | Schools (IZhO13_school) | C++14 | 119 ms | 9308 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;
typedef pair<int,int> pii;
const int MAXN=300005;
vector<pii> V;
long long pref[MAXN],suf[MAXN];
priority_queue<int> PQ;
priority_queue<int,vector<int>,greater<int> > PQ2;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N,M,S,A,B;
cin >> N >> M >> S;
for(int i=1;i<=N;i++){
cin >> A >> B;
V.push_back({A,B});
}
sort(V.begin(),V.end());
reverse(V.begin(),V.end());
//gaboleh ada A yang ga dipilih buat music/sport tp > yang dipilih untuk music
//gaboleh ada B yang ga dipilih buat music/sport tp > yang dipilih untuk sport
suf[M+S]=0;
for(int i=N-1;i>=M+S;i--)PQ.push(V[i].second);
for(int i=M+S-1;i>=M;i--){
PQ.push(V[i].second);
suf[i]=suf[i+1]+PQ.top();
PQ.pop();
}
long long ret=0;
for(int i=0;i<=M-1;i++){
pref[M-1]+=V[i].first;
PQ2.push(V[i].first-V[i].second);
}
for(int i=M;i<=M+S-1;i++){
PQ2.push(V[i].first-V[i].second);
pref[i]=pref[i-1]+V[i].first-PQ2.top();
PQ2.pop();
}
long long ans=0;
for(int i=M-1;i<=M+S-1;i++){
ans=max(ans,pref[i]+suf[i+1]);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |