Submission #889364

#TimeUsernameProblemLanguageResultExecution timeMemory
889364Hugo1729Stove (JOI18_stove)C++11
100 / 100
43 ms2532 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    int n,k; cin >> n >> k;

    ll ans=n;
    priority_queue<ll,vector<ll>,greater<ll>> p;
    int last; cin >> last;
    for(int i=1;i<n;i++) {
        int t; cin >> t;

        p.push(t-last-1);
        last=t;
    }

    int sus=n-k;
    while(sus--){
        ans+= p.top();
        p.pop();
    }

    cout << ans;


    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...