Submission #994411

#TimeUsernameProblemLanguageResultExecution timeMemory
994411vjudge1Schools (IZhO13_school)C++17
100 / 100
161 ms13900 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { 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> o(N); iota(o.begin(), o.end(), 0); sort(o.begin(), o.end(), [&](int x, int y) { return A[x] - B[x] > A[y] - B[y]; }); vector<ll> pf(N + 1), sf(N + 1); priority_queue<pair<int, int>> Q; ll sum_a = 0, sum_b = 0; for (int i = 0; i < N; i++) { Q.push({-A[o[i]], i}); sum_a += A[o[i]]; while (int(Q.size()) > M) { sum_a -= A[o[Q.top().second]]; Q.pop(); } pf[i + 1] = sum_a; } Q = priority_queue<pair<int, int>>(); for (int i = N - 1; i >= 0; i--) { Q.push({-B[o[i]], i}); sum_b += B[o[i]]; while (int(Q.size()) > S) { sum_b -= B[o[Q.top().second]]; Q.pop(); } sf[i] = sum_b; } ll answer = numeric_limits<int>::min(); for (int i = 0; i <= N; i++) { answer = max(answer, pf[i] + sf[i]); } cout << answer << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...