답안 #28477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28477 2017-07-16T06:24:56 Z 맞왜틀 맞왜틀 신나는노래~ 헤이! 나도한번 불러보자(#1216, skdudn321, choiking10) 포도주 시음 (FXCUP2_wine) C++
1 / 1
116 ms 6260 KB
#include <cstdio>
#include <algorithm>
#include <vector>
int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    std::vector<int> D(N+1);
    for(int i =1 ; i <= N; i++){
        scanf("%d",&D[i]);
    }
    std::sort(D.begin(),D.end());
    std::vector<int> ans;
    long long tot = 0;
    for(int i = 0; i<= K; i++){
        if(i%2 == 1){
            ans.push_back(D[D.size()-i/2-1]);
        }else ans.push_back(D[i/2]);

        if(ans.size() >= 2 && ans.back() - ans[ans.size()-2]>= 0){
            tot += ans.back() - ans[ans.size()-2];
        }
    }
    printf("%lld",tot);
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:6:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&K);
                        ^
wine.cpp:9:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&D[i]);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1932 KB Output is correct
2 Correct 0 ms 1932 KB Output is correct
3 Correct 0 ms 1932 KB Output is correct
4 Correct 0 ms 1932 KB Output is correct
5 Correct 0 ms 1932 KB Output is correct
6 Correct 0 ms 1932 KB Output is correct
7 Correct 0 ms 1932 KB Output is correct
8 Correct 0 ms 1932 KB Output is correct
9 Correct 0 ms 1932 KB Output is correct
10 Correct 0 ms 1932 KB Output is correct
11 Correct 0 ms 1932 KB Output is correct
12 Correct 0 ms 1932 KB Output is correct
13 Correct 0 ms 1932 KB Output is correct
14 Correct 0 ms 1932 KB Output is correct
15 Correct 0 ms 2092 KB Output is correct
16 Correct 0 ms 2092 KB Output is correct
17 Correct 3 ms 2124 KB Output is correct
18 Correct 3 ms 2124 KB Output is correct
19 Correct 6 ms 2256 KB Output is correct
20 Correct 6 ms 2256 KB Output is correct
21 Correct 16 ms 2324 KB Output is correct
22 Correct 33 ms 2464 KB Output is correct
23 Correct 33 ms 3176 KB Output is correct
24 Correct 33 ms 3176 KB Output is correct
25 Correct 116 ms 3104 KB Output is correct
26 Correct 96 ms 3376 KB Output is correct
27 Correct 86 ms 4724 KB Output is correct
28 Correct 66 ms 6260 KB Output is correct
29 Correct 86 ms 3104 KB Output is correct
30 Correct 106 ms 3956 KB Output is correct
31 Correct 89 ms 4724 KB Output is correct
32 Correct 99 ms 6260 KB Output is correct
33 Correct 0 ms 1932 KB Output is correct
34 Correct 23 ms 3176 KB Output is correct