# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28712 | 탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68) | Wine Tasting (FXCUP2_wine) | C11 | 1000 ms | 1508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
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 N, K, i, first = 0, end = 1;
int *wine;
long long int flavor = 0;
scanf("%d %d", &N, &K);
wine = (int*)malloc(sizeof(int)*N + 1);
for (i = 0; i < N; i++)
scanf("%d", &wine[i]);
QuickSort(wine, N);
for (i = 0; i < K; i = i + 2) {
if (i == 0) {
flavor = wine[N - end];
end++;
continue;
}
flavor += wine[N - end] - wine[0 + first];
end++;
first++;
}
printf("%lld", flavor);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |