답안 #278657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278657 2020-08-21T16:09:14 Z keta_tsimakuridze 학교 설립 (IZhO13_school) C++14
100 / 100
200 ms 14204 KB
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=3e5+5;
int a,b,n,n1,n2,k,curAns,Cc,c,i,ans1[N],ans[N];
pair<int,pair<int,int> >p[N];
multiset<int > cur;
 main(){
 	ios_base::sync_with_stdio(false);
	cin>>n>>n1>>n2;
	for(k=1;k<=n;k++){
		cin>>a>>b;
		p[k]={a-b,{a,b}};
	}
	sort(p+1,p+n+1);
	reverse(p+1,p+n+1);
	for(k=1;k<=n1;k++){
		 cur.insert(p[k].s.f);
		 curAns+=p[k].s.f;
	}
	ans[n1]=curAns;
	for(k=n1+1;k<=n-n2;k++){
		ans[k]=ans[k-1]; 
		if((*cur.begin())<=p[k].s.f){
			ans[k]-=(*cur.begin());
			cur.erase(cur.find(*cur.begin()));
			cur.insert(p[k].s.f);
			ans[k]+=p[k].s.f;
			
		}//cout<<k<<" "<<ans[k]<<endl;
	}cur.clear();curAns=0;
	for(k=n;k>=n-n2+1;k--){
		cur.insert(p[k].s.s);
		curAns+=p[k].s.s;
	}//cout<<cur.size()<<endl;
	ans1[n-n2+1]=curAns;
	for(k=n-n2;k>n1;k--){
		ans1[k]=ans1[k+1];
		if((*cur.begin())<=p[k].s.s){
			ans1[k]-=(*cur.begin());
			cur.erase(cur.find(*cur.begin()));
			cur.insert(p[k].s.s);
			ans1[k]+=p[k].s.s;
			
		}
	}curAns=0;
	for(k=n1;k<=n-n2;k++){
	//	cout<<k<<" "<<ans[k]<<" "<<ans1[k+1]<<endl;
	curAns=max(curAns,ans[k]+ans1[k+1]);	
	}
	
	cout<<curAns<<endl;
	
}

Compilation message

school.cpp:10:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 |  main(){
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 21 ms 2688 KB Output is correct
14 Correct 38 ms 3908 KB Output is correct
15 Correct 56 ms 6776 KB Output is correct
16 Correct 129 ms 11940 KB Output is correct
17 Correct 148 ms 10940 KB Output is correct
18 Correct 155 ms 11384 KB Output is correct
19 Correct 170 ms 12296 KB Output is correct
20 Correct 200 ms 14204 KB Output is correct