| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 47524 | ngkan146 | 학교 설립 (IZhO13_school) | C++11 | 192 ms | 41936 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// khanh best
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct school{
ll m, s, id;
school(ll m=0,ll s=0,ll id=0): m(m), s(s), id(id) {}
};
ll N,M,S;
school a[300005];
ll sum;
bool cmp(school x,school y){
return x.m - x.s < y.m - y.s;
}
struct cmpS{
bool operator ()(school x,school y){
return x.s > y.s;
}
};
struct cmpM{
bool operator ()(school x,school y){
return x.m - x.s > y.m - y.s;
}
};
struct cmpM2{
bool operator ()(school x,school y){
return x.m > y.m;
}
};
priority_queue <school,vector<school>,cmpS> pqS;
priority_queue <school,vector<school>,cmpM> pqM;
priority_queue <school,vector<school>,cmpM2> pqM2;
bool usedM[300005];
int main(){
scanf("%lld %lld %lld",&N,&M,&S);
for(int i=1;i<=N;i++)
scanf("%lld %lld",&a[i].m,&a[i].s),
sum += a[i].m,
a[i].id = i;
sort(a+1,a+N+1,cmp);
for(int i=1;i<=S;i++)
sum -= (a[i].m - a[i].s);
for(int i=1;i<=S;i++)
pqS.push(a[i]);
for(int i=S+1;i<=N;i++)
pqM.push(a[i]),
pqM2.push(a[i]);
ll zero = N - M - S;
while(zero--){
ll canS = pqS.top().s;
while(usedM[pqM.top().id]) pqM.pop();
canS += pqM.top().m - pqM.top().s;
while(usedM[pqM2.top().id]) pqM2.pop();
ll canM = pqM2.top().m;
if (canS < canM){
usedM[pqM.top().id] = 1;
sum -= canS;
pqS.pop();
pqS.push(pqM.top());
pqM.pop();
}
else{
usedM[pqM2.top().id] = 1;
sum -= canM;
pqM2.pop();
}
}
cout << sum;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
