# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1063549 | VMaksimoski008 | Schools (IZhO13_school) | C++17 | 195 ms | 16076 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>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
int n, a, b;
cin >> n >> a >> b;
vector<pii> v(n);
for(auto &x : v) cin >> x.first >> x.second;
sort(v.rbegin(), v.rend());
ll pref=0, suf=0;
priority_queue<int> pq;
for(int i=0; i<a; i++) {
pref += v[i].first;
pq.push(v[i].second - v[i].first);
}
multiset<ll> ms;
for(int i=a; i<n; i++) ms.insert(v[i].second), suf += v[i].second;
while(ms.size() > b) {
suf -= *ms.begin();
ms.erase(ms.begin());
}
ll ans = pref + suf;
for(int i=a; i<a+b; i++) {
pref += v[i].first;
pq.push(v[i].second - v[i].first);
pref += pq.top(); pq.pop();
suf -= *ms.lower_bound(v[i].second);
ms.erase(ms.lower_bound(v[i].second));
ans = max(ans, pref + suf);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |