# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092110 | juicy | Schools (IZhO13_school) | C++17 | 74 ms | 6048 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m, s; cin >> n >> m >> s;
vector<array<int, 2>> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i][0] >> a[i][1];
}
sort(a.begin(), a.end(), [&](const auto &u, const auto &v) {
return u[0] - u[1] > v[0] - v[1];
});
vector<long long> p(n);
priority_queue<int> pq;
long long sum = 0;
for (int i = 0; i < n; ++i) {
sum += a[i][0];
pq.push(-a[i][0]);
while (pq.size() > m) {
sum += pq.top();
pq.pop();
}
p[i] = sum;
}
sum = 0;
priority_queue<int>().swap(pq);
long long res = 0;
for (int i = n; ~i; --i) {
if (i < n) {
sum += a[i][1];
pq.push(-a[i][1]);
while (pq.size() > s) {
sum += pq.top();
pq.pop();
}
}
if (pq.size() == s && i >= m) {
res = max(res, sum + (i ? p[i - 1] : 0));
}
}
cout << res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |