Submission #998310

#TimeUsernameProblemLanguageResultExecution timeMemory
998310Roman70Stove (JOI18_stove)C++17
100 / 100
44 ms2776 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    ll a[n];
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }
    k--;
    ll ans = n;
    priority_queue<int>pq;
    
    
    for(int i = 1;i<n;i++){
        pq.push(a[i] - a[i-1] - 1);
    }
    
    while(pq.size() && k){
        k--;
        pq.pop();
    }
    
    while(pq.size()){
        ans += pq.top();
        pq.pop();
        
    }
    cout<<ans;
    
    
    
    


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