Submission #1250558

#TimeUsernameProblemLanguageResultExecution timeMemory
1250558bruhhhhStove (JOI18_stove)C++20
100 / 100
12 ms1864 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, k, ggg;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> xet;
    xet.reserve(n - 1);
    for (int i = 0; i + 1 < n; i++) {
        xet.push_back(a[i + 1] - a[i] - 1);
    }

    sort(xet.begin(), xet.end());
    ll ans = n;
    for (int i = 0; i < n - k; i++) {
        ans += xet[i];
    }
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...