# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28628 | 탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68) | Wine Tasting (FXCUP2_wine) | C11 | 1000 ms | 3104 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>
#include <stdlib.h>
#include <time.h>
int wine[300000];
int randomized_partition(int low, int high) {
int i, temp;
i = rand() % ((high - low) + 1) + low;
temp = wine[low];
wine[low] = wine[i];
wine[i] = temp;
return partition(low, high);
}
int partition(int low, int high) {
int i, j, pivotitem, temp;
pivotitem = wine[low];
j = low;
for (i = low + 1; i <= high; i++) {
if (wine[i] <= pivotitem) {
j++;
temp = wine[i];
wine[i] = wine[j];
wine[j] = temp;
}
}
temp = wine[low];
wine[low] = wine[j];
wine[j] = temp;
return j;
}
void quicksort(int low, int high) {
int p;
if (high > low) {
p = randomized_partition(low, high);
quicksort(low, p - 1);
quicksort(p + 1, high);
}
}
int main() {
int N, K, i, first = 0, end = 1;
long long int flavor = 0;
scanf("%d %d", &N, &K);
for (i = 0; i < N; i++)
scanf("%d", &wine[i]);
//srand(tiem(NULL));
quicksort(0, N-1);
for (i = 0; i < K; i++) {
if (i == 0) {
flavor = wine[N - end];
end++;
continue;
}
if (i % 2 == 0) {
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... |