답안 #445179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445179 2021-07-16T18:44:09 Z ritul_kr_singh 학교 설립 (IZhO13_school) C++17
100 / 100
122 ms 6740 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

int n, m, s, sum, ans;

signed main(){
	cin.tie(0)->sync_with_stdio(0);

	cin >> n >> m >> s;

	array<int, 2> a[n];
	for(auto &i : a) cin >> i[0] >> i[1];
	sort(a, a+n, [&](auto &i, auto &j){
		return i[0] - i[1] < j[0] - j[1];
	});

	priority_queue<int> q;
	for(int i=0; i<n; ++i){
		q.push(-a[i][1]);
		sum += a[i][1];
		while((int)q.size() > s) sum += q.top(), q.pop();
		a[i][1] = sum;
	}
	priority_queue<int> ().swap(q);
	sum = 0;

	for(int i=n; --i>=0; ){
		q.push(-a[i][0]);
		sum += a[i][0];
		while((int)q.size() > m) sum += q.top(), q.pop();
		ans = max(ans, sum + (i ? a[i-1][1] : 0LL));
	}

	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 13 ms 1232 KB Output is correct
14 Correct 32 ms 1900 KB Output is correct
15 Correct 59 ms 2776 KB Output is correct
16 Correct 73 ms 5280 KB Output is correct
17 Correct 87 ms 5304 KB Output is correct
18 Correct 98 ms 5724 KB Output is correct
19 Correct 108 ms 6048 KB Output is correct
20 Correct 122 ms 6740 KB Output is correct