# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092101 | juicy | Schools (IZhO13_school) | C++17 | 81 ms | 8788 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.rbegin(), a.rend());
int p = m;
priority_queue<int> x;
priority_queue<array<int, 2>> y;
long long res = 0;
for (int i = 0; i < n; ++i) {
if (i < m) {
x.push(a[i][1] - a[i][0]);
res += a[i][0];
} else {
y.push({a[i][1], i});
}
}
vector<bool> used(n);
while (s--) {
if (!x.size()) {
res += y.top()[0];
y.pop();
} else {
while (y.size() && used[y.top()[1]]) {
y.pop();
}
if (x.top() + a[p][0] > y.top()[0]) {
res += x.top() + a[p][0];
used[p++] = 1;
x.pop();
} else {
auto [v, id] = y.top(); y.pop();
res += v;
used[id] = 1;
}
}
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |