# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29353 | jjwdi0 | Wine Tasting (FXCUP2_wine) | C++11 | 119 ms | 3192 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ans;
int N, K, A[300005];
int main() {
scanf("%d %d", &N, &K);
for(int i=1; i<=N; i++) scanf("%d", A+i);
sort(A+1, A+N+1);
int pre = 0;
for(int i=1, s=1, e=N; i<=K; i++) {
if(i & 1) {
ans += A[e] - pre;
pre = A[e--];
}
else pre = A[s++];
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |