# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
638112 | tvladm2009 | Schools (IZhO13_school) | C++14 | 224 ms | 18180 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 long double ld;
const int MAX_N = 3 * 1e5;
ll a[MAX_N + 1], b[MAX_N + 1], pref[MAX_N + 1], suf[MAX_N + 1];
pair<ll, ll> c[MAX_N + 1];
multiset<ll> DS;
int n, m, s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> s;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
c[i] = make_pair(b[i] - a[i], i);
}
sort(c + 1, c + n + 1);
int sum = 0;
for (int i = 1; i <= m; i++) {
DS.insert(a[c[i].second]);
sum += a[c[i].second];
}
pref[m] = sum;
for (int i = m + 1; i <= n; i++) {
DS.insert(a[c[i].second]);
sum += a[c[i].second];
sum -= *DS.begin();
DS.erase(DS.begin());
pref[i] = sum;
}
DS.clear();
sum = 0;
for (int i = n - s + 1; i <= n; i++) {
DS.insert(b[c[i].second]);
sum += b[c[i].second];
}
suf[n - s + 1] = sum;
for (int i = n - s; i >= 1; i--) {
DS.insert(b[c[i].second]);
sum += b[c[i].second];
sum -= *DS.begin();
DS.erase(DS.begin());
suf[i] = sum;
}
ll ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, (ll)pref[i] + suf[i + 1]);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |