답안 #641603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641603 2022-09-17T09:18:36 Z andreast12 학교 설립 (IZhO13_school) C++17
35 / 100
80 ms 6308 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].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 0 ms 340 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 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 1 ms 468 KB Output isn't correct
8 Correct 2 ms 468 KB Output is correct
9 Incorrect 2 ms 468 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 12 ms 1236 KB Output isn't correct
14 Incorrect 21 ms 2260 KB Output isn't correct
15 Incorrect 37 ms 4112 KB Output isn't correct
16 Correct 48 ms 4220 KB Output is correct
17 Incorrect 60 ms 4624 KB Output isn't correct
18 Incorrect 67 ms 5144 KB Output isn't correct
19 Incorrect 72 ms 5536 KB Output isn't correct
20 Incorrect 80 ms 6308 KB Output isn't correct