# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89059 | lazarus88 | 학교 설립 (IZhO13_school) | C++14 | 2025 ms | 53280 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;
int main(){
int n,m,s,cnt=0,cnt1=0,p,q;
set <pair<int,pair <int,int> > > st,st1;
cin>>n>>m>>s;
int a[100001],b[100001];
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
st.insert({-a[i],{i,1}});
st.insert({-b[i],{i,2}});
st1.insert({-a[i],{i,1}});
st1.insert({-b[i],{i,2}});
}
p=m; q=s;
while(m>=0 && s>=0){
if(s==0 && m==0) break;
pair<int,pair<int,int> > k=*st.begin();
if(k.second.second==1){
if(m>0) {
m--;
cnt+=(-k.first);
st.erase({-a[k.second.first],{k.second.first,1}});
st.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st.erase(st.begin());
}
}
if(k.second.second==2){
if(s>0){
s--;
cnt+=(-k.first);
st.erase({-a[k.second.first],{k.second.first,1}});
st.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st.erase(st.begin());
}
}
}
st1.erase(st1.begin());
m=p; s=q;
while(m>=0 && s>=0){
if(s==0 && m==0) break;
pair<int,pair<int,int> > k=*st1.begin();
if(k.second.second==1){
if(m>0) {
m--;
cnt1+=(-k.first);
st1.erase({-a[k.second.first],{k.second.first,1}});
st1.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st1.erase(st1.begin());
}
}
if(k.second.second==2){
if(s>0){
s--;
cnt1+=(-k.first);
st1.erase({-a[k.second.first],{k.second.first,1}});
st1.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st1.erase(st1.begin());
}
}
}
cout<<max(cnt,cnt1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |