# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28494 | 탕탕탕! 핑거팁 니 맘을 겨눌게~ (#68) | Wine Tasting (FXCUP2_wine) | C11 | 6 ms | 65536 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>
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |