Submission #28443

#TimeUsernameProblemLanguageResultExecution timeMemory
28443탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68)Wine Tasting (FXCUP2_wine)C11
0 / 1
0 ms1116 KiB
#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, 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) { temp = arr[N - i]; if (i == 1) result += temp; else result += temp - prev; } else { prev = arr[i - 2]; } } printf("%d", result); }

Compilation message (stderr)

wine.c: In function 'main':
wine.c:24: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:19:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:22:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);
   ^
#Verdict Execution timeMemoryGrader output
Fetching results...