Submission #28469

#TimeUsernameProblemLanguageResultExecution timeMemory
28469탕탕탕! 핑거팁 니 맘을 겨눌게~ (#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, 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 (stderr)

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 timeMemoryGrader output
Fetching results...