Submission #28285

#TimeUsernameProblemLanguageResultExecution timeMemory
28285Official Fan of ACG (#68)Wine Tasting (FXCUP2_wine)C++14
1 / 1
99 ms3104 KiB
#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)

wine.cpp: In function 'int main()':
wine.cpp:10:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
wine.cpp:13:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...