Submission #28474

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

int wine[300000];
int compare_func(void* arg1, void* arg2) {
	return (*(int*)arg1 - *(int*)arg2);
}
int main() {
	int N, K, i, first = 0, end = 1;
	long long int flavor = 0;
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++)
		scanf("%d", &wine[i]);
	qsort(wine, N, sizeof(int), compare_func);
	for (i = 0; i < K; i++) {
		if (i == 0) {
			flavor = wine[N - end];
			end++;
			continue;
		}
		if (i % 2 == 0) {
			flavor += wine[N - end] - wine[0 + first];
			end++;
			first++;
		}
	}
	printf("%lld", flavor);
}

Compilation message

wine.c: In function 'main':
wine.c:14:30: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
  qsort(wine, N, sizeof(int), compare_func);
                              ^
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:11:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:13:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &wine[i]);
   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2288 KB Output is correct
2 Correct 0 ms 2288 KB Output is correct
3 Correct 0 ms 2288 KB Output is correct
4 Correct 0 ms 2288 KB Output is correct
5 Correct 0 ms 2288 KB Output is correct
6 Correct 0 ms 2288 KB Output is correct
7 Correct 0 ms 2288 KB Output is correct
8 Correct 0 ms 2288 KB Output is correct
9 Runtime error 0 ms 2288 KB Execution killed because of forbidden syscall sysinfo (99)
10 Halted 0 ms 0 KB -