# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092110 | juicy | Schools (IZhO13_school) | C++17 | 74 ms | 6048 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |