# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
235593 | golazcc83 | 학교 설립 (IZhO13_school) | C++14 | 176 ms | 20556 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define MINF -1000000000000000000
using namespace std;
typedef long long ll;
const int MAXN = 300001;
int N, M, S;
struct city {
ll a, b, idx;
} c[MAXN];
bool descCompA(const city &s1, const city &s2) {
if(s1.a != s2.a)
return s1.a > s2.a;
return s1.b > s2.b;
}
bool descCompB(const city &s1, const city &s2) {
return s1.b > s2.b;
}
struct ascCompBA{
bool operator()(const city &s1, const city &s2) {
if(s1.b - s1.a != s2.b - s2.a)
return s1.b - s1.a < s2.b - s2.a;
return s1.b > s2.b;
}
};
ll An[MAXN], Bn[MAXN];
int con[MAXN];
int main() {
scanf("%d %d %d", &N, &M, &S);
for(int i = 0; i < N; ++i) {
scanf("%lld %lld", &An[i], &Bn[i]);
c[i].a = An[i];
c[i].b = Bn[i];
}
sort(c, c + N, descCompA);
for(int i = 0; i < N; ++i)
c[i].idx = i;
ll res = 0;
priority_queue<city, vector<city>, ascCompBA> pqsm;
fill(con, con + M, 1);
for(int i = 0; i < M; ++i) {
res += c[i].a;
pqsm.push(c[i]);
}
for(int i = M; i < M + S; ++i) {
city tc = pqsm.top();
if(c[i].b - c[i].a >= tc.b - tc.a) {
res += c[i].b;
con[i] = 2;
}
else {
res += c[i].a + tc.b - tc.a;
pqsm.pop();
pqsm.push(c[i]);
con[i] = 1;
con[tc.idx] = 2;
}
}
priority_queue<ll, vector<ll>, greater<ll>> pqm;
for(int i = 0; i < M + S; ++i)
if(con[i] == 2)
pqm.push(c[i].b);
sort(c + M + S, c + N, descCompB);
for(int i = M + S; i < N; ++i) {
if(c[i].b > pqm.top()) {
res += c[i].b - pqm.top();
pqm.pop();
pqm.push(c[i].b);
}
else
break;
}
printf("%lld\n", res);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |