Submission #641604

# Submission time Handle Problem Language Result Execution time Memory
641604 2022-09-17T09:21:08 Z andreast12 Schools (IZhO13_school) C++17
100 / 100
85 ms 6232 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
const int mod=998244353, maxn=3e5+5;
int n, m, s;
pair<int, int> a[maxn];
priority_queue<int, vector<int>, greater<int>> pq;
ll val, pf[maxn], sf[maxn], ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> s;
	for(int i=1; i<=n; i++) cin >> a[i].fi >> a[i].se;
	sort(a+1, a+n+1, [](auto ki, auto ka) {
		return ki.fi-ki.se>ka.fi-ka.se;
	});
	for(int i=1; i<=m; i++) {
		pq.push(a[i].fi);
		val+=a[i].fi;
		if(i==m) pf[i]=val;
	}
	for(int i=m+1; i<=n; i++) {
		if(!pq.empty()&&a[i].fi>pq.top()) {
			val+=a[i].fi-pq.top();
			pq.pop();
			pq.push(a[i].fi);
		}
		pf[i]=val;
	}
	val=0;
	while(!pq.empty()) pq.pop();
	for(int i=n; i>=n-s+1; i--) {
		pq.push(a[i].se);
		val+=a[i].se;
		if(i==n-s+1) sf[i]=val;
	}
	for(int i=n-s; i>0; i--) {
		if(!pq.empty()&&a[i].se>pq.top()) {
			val+=a[i].se-pq.top();
			pq.pop();
			pq.push(a[i].se);
		}
		sf[i]=val;
	}
	for(int i=m; i<=n-s; i++) ans=max(ans, pf[i]+sf[i+1]);
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 16 ms 1128 KB Output is correct
14 Correct 22 ms 2048 KB Output is correct
15 Correct 45 ms 3984 KB Output is correct
16 Correct 47 ms 4028 KB Output is correct
17 Correct 64 ms 4560 KB Output is correct
18 Correct 65 ms 5008 KB Output is correct
19 Correct 71 ms 5380 KB Output is correct
20 Correct 85 ms 6232 KB Output is correct