Submission #875188

#TimeUsernameProblemLanguageResultExecution timeMemory
875188misu2005Stove (JOI18_stove)C++11
100 / 100
34 ms1964 KiB
#include <iostream>
#include <algorithm>

using namespace std;

long long n, k, x, v[100002], lastx, rez;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        if (i != 1) {
            v[i-1] = x-lastx-1;
        }
        lastx = x;
    }

    rez = n;
    sort(v+1, v+n);

    long long poz = n-k;
    for (long long i = 1; i <= poz; i++)
        rez += v[i];
    cout << rez;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...