답안 #84398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84398 2018-11-15T06:48:42 Z ekrem 학교 설립 (IZhO13_school) C++
100 / 100
433 ms 39740 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

typedef pair < int , int > ii;

int n, x, y;
long long ans;
ii a[N];
priority_queue < int > q;
multiset < ii > s, t;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d",&n ,&x ,&y);
	for(int i = 1; i <= n; i++)
		scanf("%d %d",&a[i].st ,&a[i].nd);
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	for(int i = 1; i <= x; i++){
		ans += a[i].st;
		q.push(a[i].nd - a[i].st);
	}
	// cout << ans << endl;
	for(int i = x + 1; i <= n; i++){
		s.insert(a[i]);
		t.insert(mp(a[i].nd, a[i].st));
	}
	while(y--){
		int frk = q.top();
		ii son = *s.rbegin();
		ii alma = *t.rbegin();
		if(frk + son.st > alma.st){
			ans += frk + son.st;
			q.pop();
			s.erase(s.find(son));
			t.erase(t.find(mp(son.nd, son.st)));
			q.push(son.nd - son.st);
		} else{
			ans += alma.st;
			t.erase(t.find(alma));
			s.erase(s.find(mp(alma.nd, alma.st)));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n ,&x ,&y);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
school.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].st ,&a[i].nd);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
4 Correct 2 ms 644 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 6 ms 940 KB Output is correct
8 Correct 4 ms 940 KB Output is correct
9 Correct 4 ms 940 KB Output is correct
10 Correct 4 ms 940 KB Output is correct
11 Correct 7 ms 1432 KB Output is correct
12 Correct 7 ms 1432 KB Output is correct
13 Correct 18 ms 2032 KB Output is correct
14 Correct 116 ms 9484 KB Output is correct
15 Correct 268 ms 20104 KB Output is correct
16 Correct 398 ms 22260 KB Output is correct
17 Correct 259 ms 23208 KB Output is correct
18 Correct 269 ms 27516 KB Output is correct
19 Correct 303 ms 32492 KB Output is correct
20 Correct 433 ms 39740 KB Output is correct