# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043871 | vjudge1 | Schools (IZhO13_school) | C++17 | 66 ms | 11476 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 file "main"
#define maxn (int) 3e5 + 5
#define pii pair<int, int>
#define ll long long
#define gb(i, j) ((i >> j) & 1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define f first
#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
if(fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
}
int n, m, t;
pii a[maxn];
ll L[maxn], R[maxn];
void solve() {
cin >> n >> m >> t;
for(int i = 1; i <= n; i ++) cin >> a[i].f >> a[i].s;
sort(a + 1, a + n + 1, [](pii& x, pii& y) {
return x.f - y.f > x.s - y.s;
});
priority_queue<int> q;
ll sum = 0;
for(int i = 1; i <= n; i ++) {
q.push( -a[i].f ), sum += a[i].f;
if(q.size() < m) L[i] = -1e18;
else if(q.size() == m) L[i] = sum;
else {
ll val = -q.top(); q.pop();
sum -= val, L[i] = sum;
}
}
while(q.size()) q.pop();
sum = 0;
for(int i = n; i >= 1; i --) {
q.push( -a[i].s ), sum += a[i].s;
if(q.size() < t) R[i] = -1e18;
else if(q.size() == t) R[i] = sum;
else {
int val = -q.top(); q.pop();
sum -= val, R[i] = sum;
}
}
ll ans = 0;
for(int i = 1; i <= n; i ++) {
ans = max(ans, L[i] + R[i + 1]);
}
cout << ans;
}
int main()
{
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |