제출 #1187736

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> t(n);
    for (int i = 0; i < n; i++) cin >> t[i];

    sort(t.begin(), t.end());

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

    sort(gaps.rbegin(), gaps.rend());

    int total = t[n - 1] + 1 - t[0];

    for (int i = 0; i < k - 1 && i < gaps.size(); i++) {
        total -= gaps[i];
    }

    cout << total << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...