Submission #28485

#TimeUsernameProblemLanguageResultExecution timeMemory
28485핑응핑응 홍신정 (#68)Wine Tasting (FXCUP2_wine)C11
1 / 1
109 ms5804 KiB
#include <stdio.h> long long int t[300000]; long long int temp[300000]; void merge(long long int A[], int low, int high) { int mid = (low + high) / 2; int i = low, j = mid + 1, k = low; while (i <= mid && j <= high) { if (A[i]<A[j]) { temp[k++] = A[i++]; } else { temp[k++] = A[j++]; } } for (; i <= mid; i++) { temp[k++] = A[i]; } for (; j <= high; j++) { temp[k++] = A[j]; } for (i = low; i <= high; i++) A[i] = temp[i]; } void mergesort(long long int A[], int low, int high) { int mid = (low + high) / 2; if (high>low) { mergesort(A, low, mid); mergesort(A, mid + 1, high); merge(A, low, high); } } int main() { int num, k, i; int start = 0, end; long long int flavor = 0, tmp=0; int flag = 1; scanf("%d %d", &num, &k); for (i = 0; i < num; i++) { scanf("%lld", &t[i]); } mergesort(t, 0, num - 1); end = num-1; while (k--) { if (flag == 1) { flavor += (t[end--]-tmp); flag = 0; } else { tmp = t[start++]; flag = 1; } } printf("%lld", flavor); return 0; }

Compilation message (stderr)

wine.c: In function 'main':
wine.c:46:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &num, &k);
  ^
wine.c:49:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &t[i]);
   ^
#Verdict Execution timeMemoryGrader output
Fetching results...