# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
992533 | tch1cherin | Schools (IZhO13_school) | C++17 | 93 ms | 14048 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;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M, S;
cin >> N >> M >> S;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
vector<int> ord(N);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) {
return A[x] - B[x] > A[y] - B[y];
});
vector<long long> pref(N + 1), suff(N + 1);
priority_queue<pair<int, int>> Q;
long long sum_a = 0, sum_b = 0;
for (int i = 0; i < N; i++) {
Q.push({-A[ord[i]], i});
sum_a += A[ord[i]];
while (int(Q.size()) > M) {
sum_a -= A[ord[Q.top().second]];
Q.pop();
}
pref[i + 1] = sum_a;
}
Q = priority_queue<pair<int, int>>();
for (int i = N - 1; i >= 0; i--) {
Q.push({-B[ord[i]], i});
sum_b += B[ord[i]];
while (int(Q.size()) > S) {
sum_b -= B[ord[Q.top().second]];
Q.pop();
}
suff[i] = sum_b;
}
long long answer = numeric_limits<int>::min();
for (int i = 0; i <= N; i++) {
answer = max(answer, pref[i] + suff[i]);
}
cout << answer << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |