제출 #755092

#제출 시각아이디문제언어결과실행 시간메모리
755092otiko_lagadzeStove (JOI18_stove)C++14
100 / 100
18 ms1368 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define pb push_back
#define endl '\n'
#define y1 y21
using namespace std;
const int inf = 1e9;
const int mxn = 2*1e5+11;
const int lg = 31;
const ll mod = 1e9+7;

void slve(){
    int n,k;
    cin>>n>>k;

    vector<int> a(n), b;
    for(int i=0; i<n; i++){
        cin>>a[i];

        if(i){
            b.pb(a[i] - a[i-1] - 1);
        }
    }

    int ans = n;
    sort(b.begin(), b.end());
    for(int i=0; i<n - k; i++){
        ans += b[i];
    }

    cout<<ans;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    ll T = 1;
    // cin>>T;
    while (T--) {
        slve();
    }
 
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...