# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29032 | cki86201 | Wine Tasting (FXCUP2_wine) | C++11 | 103 ms | 3072 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 <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;
void solve() {
int n, k;
int A[300030];
scanf("%d%d", &n, &k);
for(int i=1;i<=n;i++)scanf("%d", A+i);
sort(A+1, A+1+n);
int l = 1, r = n, t = 1;
int p = 0; ll ans = 0;
rep(a, k) {
if(t) { ans += A[r--] - p; t ^= 1; }
else { p = A[l++]; t ^= 1;}
}
printf("%lld\n", ans);
}
int main(){
int tc = 1; // scanf("%d", &tc);
for(int t=1;t<=tc;t++) {
solve();
}
return 0;
};
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |