# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96221 | Retro3014 | 학교 설립 (IZhO13_school) | C++17 | 169 ms | 8164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <queue>
using namespace std;
typedef long long ll;
#define MAX_N 300000
int N, M, S;
struct ST{
ST (int x, int y) : x(x), y(y) {}
int x, y;
bool operator <(const ST &a)const{
if(x==a.x) return y<a.y;
return x>a.x;
}
};
vector<ST> v;
priority_queue<ll> pq;
struct S2{
S2 (ll x, int y) : x(x), y(y) {}
ll x;
int y;
bool operator <(const S2 &a)const{
return a.x<x;
}
};
priority_queue<S2> pq2;
ll ans;
bool chk[MAX_N+1];
int main(){
scanf("%d%d%d", &N, &M, &S);
for(int i=0; i<N; i++){
int a, b;
scanf("%d%d", &a, &b);
v.push_back({a, b});
}sort(v.begin(), v.end());
//for(int i=0; i<N; i++){
// cout<<v[i].x<<' '<<v[i].y<<endl;
//}cout<<endl;
ll sum = 0;
for(int i=0; i<M; i++){
sum+=v[i].x;
pq.push((ll)(v[i].y-v[i].x));
}
ll sum2 = 0;
for(int i=M; i<N; i++){
if(S==0) continue;
if(pq2.size()<S){
pq2.push({(ll)v[i].y, i}); sum2+=(ll)v[i].y;
chk[i] = true;
}
else{
if(pq2.top().x<v[i].y){
sum2-=pq2.top().x; sum2+=(ll)v[i].y;
chk[pq2.top().y] = false; chk[i] = true;
pq2.pop(); pq2.push({v[i].y, i});
}
}
}
for(int i=0; i<=S; i++){
ans = max(ans, sum+sum2);
if(i==S) continue;
sum += (ll)v[M+i].x;
pq.push((ll)(v[M+i].y-v[M+i].x));
//cout<<'&'<<pq.top()<<endl;
sum += pq.top(); pq.pop();
if(chk[M+i]){
sum2 -= (ll)v[M+i].y;
}else{
//cout<<'*'<<pq2.top().x<<endl;
sum2 -= pq2.top().x;
chk[pq2.top().y] = false;
pq2.pop();
}
}
printf("%lld", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |