Submission #897771

#TimeUsernameProblemLanguageResultExecution timeMemory
897771Mr_HusanboyStove (JOI18_stove)C++17
100 / 100
17 ms2392 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()

template<typename T>
int len(T &a){
    return a.size();
}


void solve(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(auto &u : a){
        cin >> u;
    }
    int ans = a.back() - a[0] + 1;
    vector<int> dif;
    for(int i = 1; i < n; i ++){
        dif.push_back(a[i] - a[i - 1] - 1);
    }
    sort(all(dif), greater{});
    //for(auto u : dif) cout << u << ' ';
    for(int i = 0; i < k - 1; i ++){
        ans -= dif[i];
    }
    cout << ans;
}  

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int testcases = 1;

    #ifdef Tests
    cin >> testcases;
    #endif

    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else
        cout << '\n';
        cout << "________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    cout << "done" << endl;
    #endif
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...