Submission #28469

# Submission time Handle Problem Language Result Execution time Memory
28469 2017-07-16T06:17:07 Z 탕탕탕! 핑거팁 니 맘을 겨눌게~(#1190, cls327, archane5276, ly0829) Wine Tasting (FXCUP2_wine) C
0 / 1
0 ms 1116 KB
#include <stdio.h>
#include <stdlib.h>

int compare(void *first, void *second)
{
	if (*(int*)first > *(int*)second)
		return 1;
	else if (*(int*)first < *(int*)second)
		return -1;
	else
		return 0;
}

int main()
{
	int N, K, i, j = 1, k = 1;
	long long result = 0;
	int temp = 0, prev = 0;
	int *arr;
	scanf("%d %d", &N, &K);
	arr = (int*)malloc(sizeof(int)*N);
	for (i = 0; i < N; i++) {
		scanf("%d", &arr[i]);
	}
	qsort(arr, N, sizeof(int), compare);
	for (i = 1; i <= K; i++) {
		if (i % 2 == 1) {
			if (i == 1) {
				temp = arr[N - i];
				result += temp;
			}
			else {
				temp = arr[N - i + k];
				result += temp - prev;
				k++;
			}
		}
		else {
			prev = arr[i - (j + 1)];
			j++;
		}
	}
	printf("%lld", result);
}

Compilation message

wine.c: In function 'main':
wine.c:25:29: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
  qsort(arr, N, sizeof(int), compare);
                             ^
In file included from wine.c:2:0:
/usr/include/stdlib.h:764:13: note: expected '__compar_fn_t {aka int (*)(const void *, const void *)}' but argument is of type 'int (*)(void *, void *)'
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
             ^
wine.c:20:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:23:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);
   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 0 ms 1116 KB Output is correct
9 Runtime error 0 ms 1116 KB Execution killed because of forbidden syscall sysinfo (99)
10 Halted 0 ms 0 KB -