# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
138000 | beso123 | Schools (IZhO13_school) | C++14 | 2067 ms | 15896 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 int long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
int n,s,m,ans,rm,rs;
set <pii> sp,ms;
main(){
cin>>n>>s>>m;
for(int k=1;k<=n;k++){
int a,b;
cin>>a>>b;
if(rm==0 && rs==0){
if(a>b){
rs++;
sp.insert({a,b});
ans=a;
}
else{
rm++;
ms.insert({b,a});
ans=b;
}
}
else{
pii a1=*sp.begin(),b1=*ms.begin();
if(a1.x<a)
if(b1.x>=b){
if(rs==s){
sp.erase(sp.begin());
sp.insert({a,b});
ans-=a1.x;
ans+=a;
}
else{
sp.insert({a,b});
ans+=a;
rs++;
}
continue;
}
if(b1.x<b)
if(a1.x>=a){
if(rm==m){
ms.erase(ms.begin());
ms.insert({b,a});
ans-=b1.x;
ans+=b;
}
else{
ms.insert({b,a});
rm++;
ans+=b;
}
continue;
}
int cnt1=ans,cnt2=ans;
if(rs==s)
cnt1=ans-a1.x+a;
else cnt1=ans+a;
if(rm==m)
cnt2=ans-b1.x+b;
else cnt2=ans+b;
if(cnt1<ans && cnt2<ans)
continue;
if(cnt1>=cnt2){
if(rs==s){
sp.erase(sp.begin());
sp.insert({a,b});
ans-=a1.x;
ans+=a;
}
else{
sp.insert({a,b});
ans+=a;
rs++;
}
}
else{
if(rm==m){
ms.erase(ms.begin());
ms.insert({b,a});
ans-=b1.x;
ans+=b;
}
else{
ms.insert({b,a});
rm++;
ans+=b;
}
}
}
}
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |