제출 #1345934

#제출 시각아이디문제언어결과실행 시간메모리
1345934killerzaluuStove (JOI18_stove)C++20
100 / 100
16 ms2372 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<long long> t(n + 1);
    for (int i = 1; i <= n; i++) cin >> t[i];

    if (k >= n) {
        cout << n << '\n';
        return 0;
    }

    vector<long long> gap;
    for (int i = 1; i < n; i++) {
        gap.push_back(t[i + 1] - t[i] - 1);
    }

    sort(gap.begin(), gap.end(), greater<long long>());

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

    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...