# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21854 | ulna | 학교 설립 (IZhO13_school) | C++11 | 0 ms | 5540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// why am I so weak
int n, m, s;
int a[300055], b[300055];
int group[300055];
struct compare1 {
bool operator () (const int &u, const int &v) const {
return a[u] < a[v];
}
} ;
struct compare2 {
bool operator () (const int &u, const int &v) const {
return b[u] < b[v];
}
} ;
int main() {
scanf("%d %d %d", &n, &m, &s);
for (int i = 0; i < n; i++) {
scanf("%d %d", &a[i], &b[i]);
}
vector<int> vec(n);
for (int i = 0; i < n; i++) vec[i] = i;
sort(vec.begin(), vec.end(), [&] (int u, int v) {
return a[u] > a[v];
});
long long res = 0ll;
// from a->b, nothing->a, -a[i] + b[i] + a[j]
// from nothing->b, +b[j]
priority_queue<int> a;
priority_queue<int, vector<int>, compare1> c;
priority_queue<int, vector<int>, compare2> d;
for (int i = 0; i < m; i++) {
res += ::a[vec[i]];
group[vec[i]] = 1;
a.push(-::a[vec[i]] + b[vec[i]]);
}
for (int i = m; i < n; i++) {
c.push(vec[i]);
d.push(vec[i]);
}
for (int i = 0; i < s; i++) {
while (group[c.top()] != 0) c.pop();
while (group[d.top()] != 0) d.pop();
if (a.empty() || a.top() + ::a[c.top()] < b[d.top()]) {
res += b[d.top()];
group[d.top()] = 2;
d.pop();
} else {
res += a.top() + ::a[c.top()];
group[c.top()] = 1;
c.pop();
a.pop();
}
}
printf("%lld\n", res);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |