# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28794 | kajebiii | Wine Tasting (FXCUP2_wine) | C++14 | 99 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 <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
const int MAX_N = 3e5 + 100;
int N, K, Nr[MAX_N];
int main() {
cin >> N >> K;
for(int i=0; i<N; i++) scanf("%d", &Nr[i]);
sort(Nr, Nr+N);
int l = 0, r = N-1, last = 0;
ll ans = 0;
for(int i=0; i<K; i++) {
if(i % 2 == 0) {
ans += Nr[r] - last;
last = Nr[r]; r--;
} else {
ans += 0;
last = Nr[l]; l++;
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |