답안 #28320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28320 2017-07-16T04:40:49 Z 욱제한테백구주나(#1214, sgc109, wookje, joonas) 포도주 시음 (FXCUP2_wine) C++
1 / 1
206 ms 4364 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;

int N, K;
ll A[300003];
int main() {
	cin >> N >> K;
	for(int i = 0 ; i < N; i++) cin >> A[i];
	sort(A, A + N);
	int l = 0, r = N - 1;
	ll ans = 0;
	for(int cnt = 0; cnt < K - 1; cnt++){
		if(~cnt & 1) ans += A[r] - A[l], r--;
		else l++;
	}
	if(K & 1) ans += A[r];
	else ans += A[l];

	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 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 3 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 3 ms 4364 KB Output is correct
17 Correct 3 ms 4364 KB Output is correct
18 Correct 13 ms 4364 KB Output is correct
19 Correct 16 ms 4364 KB Output is correct
20 Correct 13 ms 4364 KB Output is correct
21 Correct 46 ms 4364 KB Output is correct
22 Correct 56 ms 4364 KB Output is correct
23 Correct 49 ms 4364 KB Output is correct
24 Correct 53 ms 4364 KB Output is correct
25 Correct 169 ms 4364 KB Output is correct
26 Correct 169 ms 4364 KB Output is correct
27 Correct 156 ms 4364 KB Output is correct
28 Correct 146 ms 4364 KB Output is correct
29 Correct 186 ms 4364 KB Output is correct
30 Correct 206 ms 4364 KB Output is correct
31 Correct 166 ms 4364 KB Output is correct
32 Correct 166 ms 4364 KB Output is correct
33 Correct 0 ms 4364 KB Output is correct
34 Correct 39 ms 4364 KB Output is correct