# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28285 | Official Fan of ACG (#68) | Wine Tasting (FXCUP2_wine) | C++14 | 99 ms | 3104 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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
int n, k;
scanf("%d%d", &n, &k);
vector<int> a(n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(a.begin(), a.end());
ll sum = 0;
int last = 0, p = 0, q = n - 1;
while (k > 1) {
sum += (a[q--] - last);
last = a[p++];
k -= 2;
}
if (k == 1) sum += a[q] - last;
printf("%lld\n", sum);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |