답안 #4798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4798 2014-01-03T17:11:44 Z cki86201 학교 설립 (IZhO13_school) C++
25 / 100
204 ms 7780 KB
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<functional>
using namespace std;

typedef long long ll;
int N,M,S;
bool chk[300030][2];
ll ans;

struct data{
	int x,y,c;
	bool operator<(const data &l)const{
		return c<l.c;
	}
}inp[300030];

priority_queue <int,vector<int>,greater<int> >pq1;
priority_queue <int> pq2,pq3;

bool compx(const data &a,const data &b){return a.x<b.x;}
bool compy(const data &a,const data &b){return a.y<b.y;}

int main(){
	scanf("%d%d%d",&N,&M,&S);
	int i;
	for(i=0;i<N;i++){
		scanf("%d%d",&inp[i].x,&inp[i].y);
		inp[i].c=i;
	}
	sort(inp,inp+N,compx);
	for(i=N-M-S;i<N;i++)ans += inp[i].x, chk[inp[i].c][0] = 1;
	sort(inp,inp+N,compy);
	for(i=N-M-S;i<N;i++)chk[inp[i].c][1] = 1;
	sort(inp,inp+N);
	for(i=0;i<N;i++){
		if(chk[i][0]&&chk[i][1])pq3.push(inp[i].y-inp[i].x);
		else if(chk[i][0])pq1.push(inp[i].x);
		else if(chk[i][1])pq2.push(inp[i].y);
	}
	pq2.push(-1e9),pq3.push(-1e9),pq1.push(1e9);
	for(i=0;i<S;i++){
		int a = pq3.top();
		int b = pq2.top() - pq1.top();
		if(a>b)pq3.pop(), ans += a;
		else pq2.pop(), pq1.pop(), ans += b;
	}
	printf("%lld",ans);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Incorrect 0 ms 5344 KB Output isn't correct
5 Incorrect 0 ms 5344 KB Output isn't correct
6 Incorrect 0 ms 5344 KB Output isn't correct
7 Incorrect 0 ms 5344 KB Output isn't correct
8 Correct 0 ms 5344 KB Output is correct
9 Incorrect 0 ms 5344 KB Output isn't correct
10 Incorrect 0 ms 5344 KB Output isn't correct
11 Incorrect 0 ms 5344 KB Output isn't correct
12 Incorrect 0 ms 5344 KB Output isn't correct
13 Incorrect 24 ms 5476 KB Output isn't correct
14 Incorrect 56 ms 5796 KB Output isn't correct
15 Incorrect 104 ms 5344 KB Output isn't correct
16 Correct 148 ms 6884 KB Output is correct
17 Incorrect 152 ms 7224 KB Output isn't correct
18 Incorrect 160 ms 6628 KB Output isn't correct
19 Incorrect 172 ms 7652 KB Output isn't correct
20 Incorrect 204 ms 7780 KB Output isn't correct