답안 #641602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641602 2022-09-17T09:16:27 Z andreast12 학교 설립 (IZhO13_school) C++17
35 / 100
82 ms 9740 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(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(a[i].se>pq.top()) {
			val+=a[i].se-pq.top();
			pq.pop();
			pq.push(a[i].fi);
		}
		sf[i]=val;
	}
	for(int i=m; i<=n-s; i++) ans=max(ans, pf[i]+sf[i+1]);
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 2 ms 384 KB Output isn't correct
8 Correct 2 ms 480 KB Output is correct
9 Incorrect 2 ms 388 KB Output isn't correct
10 Incorrect 2 ms 468 KB Output isn't correct
11 Incorrect 2 ms 468 KB Output isn't correct
12 Incorrect 2 ms 468 KB Output isn't correct
13 Incorrect 13 ms 1504 KB Output isn't correct
14 Incorrect 21 ms 2880 KB Output isn't correct
15 Incorrect 38 ms 5772 KB Output isn't correct
16 Correct 49 ms 6036 KB Output is correct
17 Incorrect 69 ms 7116 KB Output isn't correct
18 Incorrect 72 ms 7924 KB Output isn't correct
19 Incorrect 73 ms 8376 KB Output isn't correct
20 Incorrect 82 ms 9740 KB Output isn't correct