Submission #1140464

#TimeUsernameProblemLanguageResultExecution timeMemory
1140464vikofazStove (JOI18_stove)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    // freopen("input","r",stdin);
    // freopen("output","w",stdout);    
    int n,k;
    cin >> n >> k;
    int a, total =1;

    vector<int> v;

    for(int i=1; i<=n;i++){
        int b;
        cin >> b;
        if(i>1){
            v.push_back(b-a-1);
            total += b-a;
        }
        a=b;
    }
    sort(v.rbegin(),v.rend());
    for(int i=0;i<n-k;i++){
        total -= v[i];
    }
    cout << total << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...