Submission #28494

#TimeUsernameProblemLanguageResultExecution timeMemory
28494탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68)Wine Tasting (FXCUP2_wine)C11
0 / 1
6 ms65536 KiB
#include <stdio.h> int N, K; void merge_sort(int array[], int left, int right); void merge(int num[], int left, int mid, int right); void merge_sort(int array[], int left, int right) { int mid; if (left < right) { mid = (left + right) / 2; merge_sort(array, left, mid); merge_sort(array, mid + 1, right); merge(array, left, mid, right); } } void merge(int array[], int left, int mid, int right) { int i, j, k, m; i = left; j = mid + 1; k = left; int *tempArray; tempArray = (int*)malloc(sizeof(int)*N); while (i <= mid && j <= right) { if (array[i] < array[j]) { tempArray[k] = array[i]; i++; } else { tempArray[k] = array[j]; j++; } k++; } if (i > mid) { for (m = j; m <= right; m++) { tempArray[k] = array[m]; k++; } } else { for (m = i; m <= mid; m++) { tempArray[k] = array[m]; k++; } } for (m = left; m <= right; m++) { array[m] = tempArray[m]; } } int main() { int 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]); } merge_sort(arr, 0, N - 1); 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 'merge':
wine.c:27:20: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
  tempArray = (int*)malloc(sizeof(int)*N);
                    ^
wine.c:27:20: warning: incompatible implicit declaration of built-in function 'malloc'
wine.c:27:20: note: include '<stdlib.h>' or provide a declaration of 'malloc'
wine.c: In function 'main':
wine.c:64:14: warning: incompatible implicit declaration of built-in function 'malloc'
  arr = (int*)malloc(sizeof(int)*N);
              ^
wine.c:64:14: note: include '<stdlib.h>' or provide a declaration of 'malloc'
wine.c:63:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:66: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...