제출 #391745

#제출 시각아이디문제언어결과실행 시간메모리
391745timmyfengStove (JOI18_stove)C++17
100 / 100
22 ms2076 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 100000;

int t[N], gap[N];

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

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; ++i) {
        cin >> t[i];
        if (i > 0) {
            gap[i] = t[i] - t[i - 1] - 1;
        }
    }

    int ans = t[n - 1] + 1 - t[0];
    sort(gap + 1, gap + n, greater<int>());
    for (int i = 0; i < k; ++i) {
        ans -= gap[i];
    }

    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...