답안 #28480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28480 2017-07-16T06:25:31 Z 핑응핑응 홍신정(#1134, owlur, elxmakdldj, haro199) 포도주 시음 (FXCUP2_wine) C
0 / 1
1000 ms 4744 KB
#include <stdio.h>

long long int t[300000];

int Partition(long long int num[], int p, int r) {
	long long int x = num[r], tmp;
	int i = p - 1;
	int j;

	for (j = p; j<r; j++) {
		if (num[j] <= x) {
			i = i + 1;
			tmp = num[i];
			num[i] = num[j];
			num[j] = tmp;
		}
	}
	tmp = num[i + 1];
	num[i + 1] = num[r];
	num[r] = tmp;

	return i + 1;
}

void Quicksort(long long int num[], int p, int r) {
	int q;

	if (p<r) {
		q = Partition(num, p, r);
		Quicksort(num, p, q - 1);
		Quicksort(num, q + 1, r);
	}
}

int main() {
	int num, k, i;
	int start = 0, end;
	long long int flavor = 0, tmp=0;
	int flag = 1;

	scanf("%d %d", &num, &k);
	
	for (i = 0; i < num; i++) {
		scanf("%lld", &t[i]);
	}

	Quicksort(t, 0, num - 1);

	end = num-1;
	while (k--) {
		if (flag == 1) {
			flavor += (t[end--]-tmp);
			flag = 0;
		}
		else {
			tmp = t[start++];
			flag = 1;
		}
	}

	printf("%lld", flavor);

	return 0;
}

Compilation message

wine.c: In function 'main':
wine.c:41:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &num, &k);
  ^
wine.c:44:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &t[i]);
   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Correct 0 ms 3460 KB Output is correct
4 Correct 0 ms 3460 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
6 Correct 0 ms 3460 KB Output is correct
7 Correct 0 ms 3460 KB Output is correct
8 Correct 0 ms 3460 KB Output is correct
9 Correct 0 ms 3460 KB Output is correct
10 Correct 0 ms 3460 KB Output is correct
11 Correct 0 ms 3460 KB Output is correct
12 Correct 0 ms 3460 KB Output is correct
13 Correct 0 ms 3460 KB Output is correct
14 Correct 0 ms 3460 KB Output is correct
15 Correct 16 ms 3572 KB Output is correct
16 Correct 0 ms 3460 KB Output is correct
17 Correct 616 ms 4744 KB Output is correct
18 Correct 526 ms 4744 KB Output is correct
19 Correct 6 ms 3460 KB Output is correct
20 Correct 6 ms 3460 KB Output is correct
21 Execution timed out 1000 ms 4172 KB Execution timed out
22 Halted 0 ms 0 KB -