# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89059 | lazarus88 | 학교 설립 (IZhO13_school) | C++14 | 2025 ms | 53280 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |