Submission #1096968

#TimeUsernameProblemLanguageResultExecution timeMemory
1096968codexistentSchools (IZhO13_school)C++14
60 / 100
145 ms12248 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MAXN 300005 #define FOR(i, a, b) for(ll i = a; i <= b; i++) ll n, t[2], pfx[MAXN], r = 0; vector<array<ll, 2>> v(MAXN); int main(){ cin >> n >> t[0] >> t[1]; FOR(i, 1, n) cin >> v[i][0] >> v[i][1]; sort(begin(v) + 1, begin(v) + 1 + n, [&](const auto &a, const auto &b) { return a[0] - a[1] > b[0] - b[1]; }); priority_queue<ll> pq; pfx[0] = 0; FOR(i, 1, n){ pfx[i] = pfx[i - 1]; pfx[i] += v[i][0], pq.push(-v[i][0]); while((ll)pq.size() > t[0]) pfx[i] += pq.top(), pq.pop(); } priority_queue<ll>().swap(pq); ll sfx = 0; for(ll i = n; i >= 1; i--){ sfx += v[i][1]; pq.push(-v[i][1]); while((ll)pq.size() > t[1]) sfx += pq.top(), pq.pop(); if((ll)pq.size() == t[1] && i - 1 >= t[1]) r = max(r, sfx + pfx[i - 1]); } cout << r << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...