Submission #28590

#TimeUsernameProblemLanguageResultExecution timeMemory
28590탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68)Wine Tasting (FXCUP2_wine)C11
0 / 1
0 ms3460 KiB
#include <stdio.h> int wine[300000], flag[300000]; int main() { int N, K, i, j, min, max, pre_min, min_index, max_index; long long int flavor = 0; scanf("%d %d", &N, &K); for (i = 0; i < N; i++) scanf("%d", &wine[i]); i = 0; while (i < K) { min = 1000000001, max = -1; for (j = 0; j < N; j++) { if (max < wine[j] && flag[j] == 0) { max = wine[j]; max_index = j; } if (min > wine[j] && flag[j] == 0) { min = wine[j]; min_index = j; } } flag[max_index] = 1, flag[min_index] = 1; if (i == 0) { flavor = max; pre_min = min; i++; continue; } else flavor += (max - pre_min); pre_min = min; i = i + 2; } printf("%lld", flavor); }

Compilation message (stderr)

wine.c: In function 'main':
wine.c:8:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:10:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &wine[i]);
   ^
wine.c:18:19: warning: 'max_index' may be used uninitialized in this function [-Wmaybe-uninitialized]
   flag[max_index] = 1, flag[min_index] = 1;
                   ^
wine.c:18:40: warning: 'min_index' may be used uninitialized in this function [-Wmaybe-uninitialized]
   flag[max_index] = 1, flag[min_index] = 1;
                                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...