제출 #1256855

#제출 시각아이디문제언어결과실행 시간메모리
1256855kawhietStove (JOI18_stove)C++20
100 / 100
13 ms1096 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> d(n - 1);
    for (int i = 0; i < n - 1; i++) {
        d[i] = a[i + 1] - a[i] - 1;
    }
    sort(d.rbegin(), d.rend());
    int ans = a[n - 1] - a[0] + 1;
    for (int i = 0; i < k - 1; i++) {
        ans -= d[i];
    }
    cout << ans << '\n';

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