# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672990 | viwlesxq | Schools (IZhO13_school) | C++17 | 2074 ms | 13500 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;
typedef long long ll;
typedef string str;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
const int N = 3e5;
ll pref[N], suff[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, s;
cin >> n >> m >> s;
int a[n], b[n];
vector <pair <int, int>> v;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
v.pb({a[i] - b[i], i});
}
sort(rall(v));
multiset <int> cur;
ll sum = 0;
for (int i = 0; i < m; i++) {
cur.insert(a[v[i].S]);
sum += a[v[i].S];
}
pref[m-1] = sum;
for (int i = m; i < n; i++) {
int can = a[v[i].S];
if (*cur.begin() < can) {
sum -= *cur.begin();
cur.erase(cur.begin());
cur.insert(can);
sum += can;
}
pref[i] = sum;
}
sum = 0;
cur.clear();
for (int i = n - 1; i >= n - s; i--) {
cur.insert(b[v[i].S]);
sum += b[v[i].S];
}
suff[n-s] = sum;
for (int i = n - s - 1; i >= 0; i--) {
int can = b[v[i].S];
if (*cur.begin() < can) {
sum -= *cur.begin();
cur.erase(cur.begin());
cur.insert(can);
sum += can;
}
suff[i] = sum;
}
ll ans = 0;
for (int i = m - 1; i < n - s; i++) {
ans = max(ans, pref[i] + suff[i+1]);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |