답안 #28242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28242 2017-07-16T04:07:33 Z /*Sn*/(#1133, jjwdi0) 포도주 시음 (FXCUP2_wine) C++11
1 / 1
106 ms 3192 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll ans;
int N, K, A[300005];

int main() {
    scanf("%d %d", &N, &K);
    for(int i=1; i<=N; i++) scanf("%d", A+i);
    sort(A+1, A+N+1);
    int pre = 0;
    for(int i=1, s=1, e=N; i<=K; i++) {
        if(i & 1) {
            ans += A[e] - pre;
            pre = A[e--];
        }
        else pre = A[s++];
    }
    printf("%lld\n", ans);
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &K);
                           ^
wine.cpp:10:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d", A+i);
                                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3192 KB Output is correct
2 Correct 0 ms 3192 KB Output is correct
3 Correct 0 ms 3192 KB Output is correct
4 Correct 0 ms 3192 KB Output is correct
5 Correct 0 ms 3192 KB Output is correct
6 Correct 0 ms 3192 KB Output is correct
7 Correct 0 ms 3192 KB Output is correct
8 Correct 0 ms 3192 KB Output is correct
9 Correct 0 ms 3192 KB Output is correct
10 Correct 0 ms 3192 KB Output is correct
11 Correct 0 ms 3192 KB Output is correct
12 Correct 0 ms 3192 KB Output is correct
13 Correct 0 ms 3192 KB Output is correct
14 Correct 0 ms 3192 KB Output is correct
15 Correct 0 ms 3192 KB Output is correct
16 Correct 0 ms 3192 KB Output is correct
17 Correct 3 ms 3192 KB Output is correct
18 Correct 3 ms 3192 KB Output is correct
19 Correct 6 ms 3192 KB Output is correct
20 Correct 6 ms 3192 KB Output is correct
21 Correct 13 ms 3192 KB Output is correct
22 Correct 29 ms 3192 KB Output is correct
23 Correct 26 ms 3192 KB Output is correct
24 Correct 23 ms 3192 KB Output is correct
25 Correct 79 ms 3192 KB Output is correct
26 Correct 96 ms 3192 KB Output is correct
27 Correct 99 ms 3192 KB Output is correct
28 Correct 59 ms 3192 KB Output is correct
29 Correct 93 ms 3192 KB Output is correct
30 Correct 106 ms 3192 KB Output is correct
31 Correct 76 ms 3192 KB Output is correct
32 Correct 86 ms 3192 KB Output is correct
33 Correct 0 ms 3192 KB Output is correct
34 Correct 16 ms 3192 KB Output is correct