Submission #28509

#TimeUsernameProblemLanguageResultExecution timeMemory
28509탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68)Wine Tasting (FXCUP2_wine)C11
0 / 1
0 ms1116 KiB
#include <stdio.h> int N, K; void swap(int num1, int num2) { int temp = num1; num1 = num2; num2 = temp; } void q_sort(int numbers[], int left, int right) { int pivot, l_hold, r_hold, median; l_hold = left; r_hold = right; median = (left + right) / 2; swap(numbers[left], numbers[median]); pivot = numbers[left]; while (left < right) { while ((numbers[right] >= pivot) && (left < right)) right--; if (left != right) { numbers[left] = numbers[right]; } while ((numbers[left] <= pivot) && (left < right)) left++; if (left != right) { numbers[right] = numbers[left]; right--; } } numbers[left] = pivot; pivot = left; left = l_hold; right = r_hold; if (left < pivot) q_sort(numbers, left, pivot - 1); if (right > pivot) q_sort(numbers, pivot + 1, right); } void QuickSort(int numbers[], int array_size) { q_sort(numbers, 0, array_size - 1); } 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]); } QuickSort(arr, N); printf("%d %d %d", arr[0], arr[2], arr[4]); 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:61:14: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
  arr = (int*)malloc(sizeof(int)*N);
              ^
wine.c:61:14: warning: incompatible implicit declaration of built-in function 'malloc'
wine.c:61:14: note: include '<stdlib.h>' or provide a declaration of 'malloc'
wine.c:60:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ^
wine.c:63: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...