Submission #28507

# Submission time Handle Problem Language Result Execution time Memory
28507 2017-07-16T06:48:08 Z Shocking Hot(#1200, khsoo01) Wine Tasting (FXCUP2_wine) C++14
1 / 1
106 ms 4364 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, a[300005];

int main()
{
	scanf("%lld%lld",&n,&k);
	if(k%2 == 0) k--;
	for(ll i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
	}
	sort(a+1, a+1+n);
	ll ans = 0;
	for(ll i=1;i<=(k+1)/2;i++) {
		ans += a[n-i+1];
	}
	for(ll i=1;i<=k/2;i++) {
		ans -= a[i];
	}
	printf("%lld\n",ans);
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:8:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&k);
                         ^
wine.cpp:11:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4364 KB Output is correct
2 Correct 0 ms 4364 KB Output is correct
3 Correct 0 ms 4364 KB Output is correct
4 Correct 0 ms 4364 KB Output is correct
5 Correct 0 ms 4364 KB Output is correct
6 Correct 0 ms 4364 KB Output is correct
7 Correct 0 ms 4364 KB Output is correct
8 Correct 0 ms 4364 KB Output is correct
9 Correct 0 ms 4364 KB Output is correct
10 Correct 0 ms 4364 KB Output is correct
11 Correct 0 ms 4364 KB Output is correct
12 Correct 0 ms 4364 KB Output is correct
13 Correct 0 ms 4364 KB Output is correct
14 Correct 0 ms 4364 KB Output is correct
15 Correct 0 ms 4364 KB Output is correct
16 Correct 0 ms 4364 KB Output is correct
17 Correct 3 ms 4364 KB Output is correct
18 Correct 0 ms 4364 KB Output is correct
19 Correct 6 ms 4364 KB Output is correct
20 Correct 9 ms 4364 KB Output is correct
21 Correct 26 ms 4364 KB Output is correct
22 Correct 19 ms 4364 KB Output is correct
23 Correct 26 ms 4364 KB Output is correct
24 Correct 26 ms 4364 KB Output is correct
25 Correct 89 ms 4364 KB Output is correct
26 Correct 73 ms 4364 KB Output is correct
27 Correct 96 ms 4364 KB Output is correct
28 Correct 66 ms 4364 KB Output is correct
29 Correct 103 ms 4364 KB Output is correct
30 Correct 89 ms 4364 KB Output is correct
31 Correct 106 ms 4364 KB Output is correct
32 Correct 93 ms 4364 KB Output is correct
33 Correct 0 ms 4364 KB Output is correct
34 Correct 13 ms 4364 KB Output is correct