# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676298 | vjudge1 | Schools (IZhO13_school) | C++17 | 125 ms | 8992 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;
#define f first
#define s second
#define NMAX 300000
typedef long long ll;
int n, M, S;
pair<ll, ll> arr[NMAX + 10];
ll pre[NMAX + 10], sur[NMAX + 10];
priority_queue <ll, vector<ll>, greater<ll> > pq;
bool comp(pair<ll, ll> &u, pair<ll, ll> &v) {
return (u.f - u.s < v.f - v.s);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("hth.inp", "r")) {
freopen("hth.inp", "r", stdin);
freopen("hth.out", "w", stdout);
}
cin >> n >> M >> S;
for(int i = 1; i <= n; i++) {
cin >> arr[i].f >> arr[i].s;
}
sort(arr + 1, arr + 1 + n, comp);
long long sum = 0;
for(int i = 1; i <= S; i++) {
sum += arr[i].s;
pq.push(arr[i].s);
}
pre[S] = sum;
for(int i = S + 1; i <= n; i++) {
pq.push(arr[i].s);
sum += arr[i].s;
sum -= pq.top();
pq.pop();
pre[i] = sum;
}
while(pq.size())
pq.pop();
sum = 0;
for(int i = n; i >= n - M + 1; i --) {
sum += arr[i].f;
pq.push(arr[i].f);
}
sur[n - M + 1] = sum;
for(int i = n - M; i > 0; i--) {
pq.push(arr[i].f);
sum += arr[i].f;
sum -= pq.top();
pq.pop();
sur[i] = sum;
}
ll MAX = 0;
for(int i = S; i <= n - M; i++)
MAX = max(MAX, pre[i] + sur[i + 1]);
cout << MAX;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |