# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673599 | moday_morning | Schools (IZhO13_school) | C++17 | 131 ms | 10772 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 fr first
#define sc second
#define int long long
using namespace std;
const int N = 300005;
int v[N], v1[N];
pair <int, int> a[N];
void solve () {
int n, x, y;
cin >> n >> x >> y;
for(int i = 1; i <= n; i++) {
cin >> a[i].fr >> a[i].sc;
}
sort(a+1, a+n+1, [] (pair <int, int> a, pair <int, int> b) -> bool {return a.fr - a.sc > b.fr - b.sc;});
priority_queue<int, vector<int>, greater<int>> q;
int sum = 0;;
for (int i = 1; i <= n; i++) {
sum += a[i].fr;
q.push(a[i].fr);
if(q.size() > x) {
sum -= q.top();
q.pop();
}
v[i] = sum;
}
while (!q.empty()) {
q.pop();
sum = 0;
}
for (int i = n; i >= 1; i--) {
sum += a[i].sc;
q.push(a[i].sc);
if (q.size() > y) {
sum -= q.top();
q.pop();
}
v1[i] = sum;
}
int mx = 0;
for (int i = x; i <= n-y; i++) {
mx = max(mx, v[i] + v1[i+1]);
}
cout << mx << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |