# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28320 | 욱제한테백구주나 (#68) | Wine Tasting (FXCUP2_wine) | C++98 | 206 ms | 4364 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;
typedef long long ll;
const int mod = 1e9+7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
int N, K;
ll A[300003];
int main() {
cin >> N >> K;
for(int i = 0 ; i < N; i++) cin >> A[i];
sort(A, A + N);
int l = 0, r = N - 1;
ll ans = 0;
for(int cnt = 0; cnt < K - 1; cnt++){
if(~cnt & 1) ans += A[r] - A[l], r--;
else l++;
}
if(K & 1) ans += A[r];
else ans += A[l];
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |