제출 #146080

#제출 시각아이디문제언어결과실행 시간메모리
146080MathStudent2002Stove (JOI18_stove)C++14
100 / 100
128 ms6052 KiB
//wait darn

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef set<ll>::iterator slt;

ll st,fi;
multiset<ll> df;
ll K;

void input() {
    int N; cin >> N >> K;

    ll pre, cur;
    for(int i = 0; i < N; i++) {
        cin >> cur;
        if(i == 0) st = cur;
        else df.insert(pre-cur);

        if(i == N-1) fi = cur+1;
        else pre = cur+1;
    }
}

void solve() {
    K--;
    ll ans = fi-st;
    int i = 0;
    slt it = df.begin();
    for(; i < K; i++, it++) {ans += (*it);}
    cout << ans << endl;
}

int main() {
    input();
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...