답안 #28445

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

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:9:9: warning: unused variable 'mval' [-Wunused-variable]
     int mval = 0;
         ^
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:11: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 Incorrect 0 ms 1932 KB Output isn't correct
4 Halted 0 ms 0 KB -