Submission #945388

#TimeUsernameProblemLanguageResultExecution timeMemory
945388KasymKStove (JOI18_stove)C++17
100 / 100
43 ms2424 KiB
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int &i : v)
        cin >> i;
    if(k == 1){
        cout << v.back() + 1 - v.front() << "\n";
        return 0;
    }
    // int div = ceil(n/2);
    // biz aralaryny yakynlasdyrjak bolyas
    int ans = v.back() + 1 - v.front();
    vector<int> tap;
    for(int i = 0; i < n - 1; ++i){
        int diff = abs(v[i + 1] - v[i]);
        tap.push_back(diff);
    }
    k--;
    sort(tap.begin(), tap.end(), greater<int> ());
    for(int i = 1; i <= k; ++i)
        ans -= tap[i - 1];
    ans += k;
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...