제출 #718322

#제출 시각아이디문제언어결과실행 시간메모리
718322mshandilyaStove (JOI18_stove)C++17
100 / 100
18 ms2264 KiB
//required macros and template
#include <bits/stdc++.h>
using namespace std;

//type definitions
#define vc vector
typedef vc<int> vi;

//main method
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k, ans;
    cin>>n>>k;
    ans = n;
    vi t(n), x;
    for(int i = 0; i<n; i++) {
        cin >> t[i];
        if(i and t[i]!=t[i-1]+1)
            x.push_back(t[i]-t[i-1]-1);
    }
    sort(x.begin(), x.end());
    for(int i = x.size()-k; i>=0; i--)
        ans += x[i];
    cout<<ans<<"\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...