답안 #90932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90932 2018-12-25T08:57:15 Z kylych03 학교 설립 (IZhO13_school) C++14
100 / 100
336 ms 22268 KB
#include <bits/stdc++.h>
#define int long long
#define sc second
#define fr first
 
 
using namespace std;
pair <int, pair<int, int> > ar[300001];
int pr[300002], sf[300002];
multiset <int> st1, st2;
main()
{
	int n,a,b;
	cin>>n>>a>>b;
	
	for(int i=0;i<n;i++){
		cin>>ar[i].sc.fr>>ar[i].sc.sc;
		
		ar[i].fr=ar[i].sc.sc - ar[i].sc.fr;
	}
	
	sort(ar,ar+n);
	int sum=0;
	for(int i=0;i<n;i++){
		if(i<a){
			sum+=ar[i].sc.fr;
			pr[i]=sum;
			st1.insert(ar[i].sc.fr);
		}
		else{
			sum+=ar[i].sc.fr;
			st1.insert(ar[i].sc.fr);
			sum-=(*st1.begin());
			pr[i]=sum;
			st1.erase(st1.begin());
			
		}
	}
	sum=0;
	for(int i=n-1;i>=0;i--){
		if(n-b <= i){
			sum+=ar[i].sc.sc;
			sf[i]=sum;
			st2.insert(ar[i].sc.sc);
		}
		else{
			sum+=ar[i].sc.sc;
			st2.insert(ar[i].sc.sc);
			sum-=(*st2.begin());
			sf[i]=sum;
			st2.erase(st2.begin());
		}
	}
	int mx=0;
	for(int i= max(0LL,a-1);i<n-b;i++)
		mx=max(pr[i] + sf[i+1],mx);
	if(a==0)
		mx=max(sf[0],mx);
	
	cout<<mx<<endl;	
}

Compilation message

school.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 5 ms 856 KB Output is correct
8 Correct 5 ms 1128 KB Output is correct
9 Correct 6 ms 1128 KB Output is correct
10 Correct 6 ms 1128 KB Output is correct
11 Correct 6 ms 1128 KB Output is correct
12 Correct 6 ms 1128 KB Output is correct
13 Correct 35 ms 3580 KB Output is correct
14 Correct 69 ms 5044 KB Output is correct
15 Correct 125 ms 7104 KB Output is correct
16 Correct 211 ms 16052 KB Output is correct
17 Correct 264 ms 18044 KB Output is correct
18 Correct 277 ms 18256 KB Output is correct
19 Correct 300 ms 19936 KB Output is correct
20 Correct 336 ms 22268 KB Output is correct