Submission #28485

# Submission time Handle Problem Language Result Execution time Memory
28485 2017-07-16T06:31:33 Z 핑응핑응 홍신정(#1134, owlur, elxmakdldj, haro199) Wine Tasting (FXCUP2_wine) C
1 / 1
109 ms 5804 KB
#include <stdio.h>

long long int t[300000];
long long int temp[300000];

void merge(long long int A[], int low, int high) {

	int mid = (low + high) / 2;
	int i = low, j = mid + 1, k = low;

	while (i <= mid && j <= high) {
		if (A[i]<A[j]) {
			temp[k++] = A[i++];
		}
		else {
			temp[k++] = A[j++];
		}
	}

	for (; i <= mid; i++) {
		temp[k++] = A[i];
	}
	for (; j <= high; j++) {
		temp[k++] = A[j];
	}
	for (i = low; i <= high; i++)
		A[i] = temp[i];
}

void mergesort(long long int A[], int low, int high) {
	int mid = (low + high) / 2;

	if (high>low) {
		mergesort(A, low, mid);
		mergesort(A, mid + 1, high);
		merge(A, low, high);
	}
}

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]);
	}

	mergesort(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:46:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &num, &k);
  ^
wine.c:49:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &t[i]);
   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5804 KB Output is correct
2 Correct 0 ms 5804 KB Output is correct
3 Correct 0 ms 5804 KB Output is correct
4 Correct 0 ms 5804 KB Output is correct
5 Correct 0 ms 5804 KB Output is correct
6 Correct 0 ms 5804 KB Output is correct
7 Correct 0 ms 5804 KB Output is correct
8 Correct 0 ms 5804 KB Output is correct
9 Correct 0 ms 5804 KB Output is correct
10 Correct 0 ms 5804 KB Output is correct
11 Correct 0 ms 5804 KB Output is correct
12 Correct 0 ms 5804 KB Output is correct
13 Correct 0 ms 5804 KB Output is correct
14 Correct 0 ms 5804 KB Output is correct
15 Correct 0 ms 5804 KB Output is correct
16 Correct 0 ms 5804 KB Output is correct
17 Correct 6 ms 5804 KB Output is correct
18 Correct 6 ms 5804 KB Output is correct
19 Correct 9 ms 5804 KB Output is correct
20 Correct 6 ms 5804 KB Output is correct
21 Correct 36 ms 5804 KB Output is correct
22 Correct 36 ms 5804 KB Output is correct
23 Correct 29 ms 5804 KB Output is correct
24 Correct 29 ms 5804 KB Output is correct
25 Correct 89 ms 5804 KB Output is correct
26 Correct 109 ms 5804 KB Output is correct
27 Correct 103 ms 5804 KB Output is correct
28 Correct 56 ms 5804 KB Output is correct
29 Correct 93 ms 5804 KB Output is correct
30 Correct 93 ms 5804 KB Output is correct
31 Correct 96 ms 5804 KB Output is correct
32 Correct 103 ms 5804 KB Output is correct
33 Correct 0 ms 5804 KB Output is correct
34 Correct 19 ms 5804 KB Output is correct