제출 #28474

#제출 시각아이디문제언어결과실행 시간메모리
28474탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68)포도주 시음 (FXCUP2_wine)C11
0 / 1
0 ms2288 KiB
#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); }

컴파일 시 표준 에러 (stderr) 메시지

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