Submission #28389

# Submission time Handle Problem Language Result Execution time Memory
28389 2017-07-16T05:10:19 Z lyzqm123(#1136, lyzqm123) Wine Tasting (FXCUP2_wine) C++11
1 / 1
109 ms 3460 KB
#include <cstdio>
#include <algorithm>
using namespace std;
long long arr[300001];
int main() {
	int N, K;
	scanf("%d%d", &N, &K);
	for (int n = 0;n < N;n++) scanf("%lld", &arr[n]);
	sort(arr, arr + N);
	
	long long ans = arr[N - 1];K--;
	int l = 0, r = N - 2;
	while (K - 2 >= 0 && l <= r) {
		ans += arr[r] - arr[l];
		K -= 2;
		r--;
		l++;
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:7: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:8:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int n = 0;n < N;n++) scanf("%lld", &arr[n]);
                                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 0 ms 3460 KB Output is correct
3 Correct 0 ms 3460 KB Output is correct
4 Correct 0 ms 3460 KB Output is correct
5 Correct 0 ms 3460 KB Output is correct
6 Correct 0 ms 3460 KB Output is correct
7 Correct 0 ms 3460 KB Output is correct
8 Correct 0 ms 3460 KB Output is correct
9 Correct 0 ms 3460 KB Output is correct
10 Correct 0 ms 3460 KB Output is correct
11 Correct 0 ms 3460 KB Output is correct
12 Correct 0 ms 3460 KB Output is correct
13 Correct 0 ms 3460 KB Output is correct
14 Correct 0 ms 3460 KB Output is correct
15 Correct 0 ms 3460 KB Output is correct
16 Correct 0 ms 3460 KB Output is correct
17 Correct 3 ms 3460 KB Output is correct
18 Correct 9 ms 3460 KB Output is correct
19 Correct 3 ms 3460 KB Output is correct
20 Correct 3 ms 3460 KB Output is correct
21 Correct 19 ms 3460 KB Output is correct
22 Correct 26 ms 3460 KB Output is correct
23 Correct 26 ms 3460 KB Output is correct
24 Correct 26 ms 3460 KB Output is correct
25 Correct 89 ms 3460 KB Output is correct
26 Correct 86 ms 3460 KB Output is correct
27 Correct 83 ms 3460 KB Output is correct
28 Correct 46 ms 3460 KB Output is correct
29 Correct 89 ms 3460 KB Output is correct
30 Correct 93 ms 3460 KB Output is correct
31 Correct 89 ms 3460 KB Output is correct
32 Correct 109 ms 3460 KB Output is correct
33 Correct 0 ms 3460 KB Output is correct
34 Correct 16 ms 3460 KB Output is correct