제출 #1014711

#제출 시각아이디문제언어결과실행 시간메모리
1014711avighnaStove (JOI18_stove)C++17
100 / 100
38 ms3020 KiB
#include <bits/stdc++.h>

typedef long long ll;

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector<ll> a(n);
    for (auto &i : a) {
        std::cin >> i;
    }
    std::vector<int> gaps;
    for (int i = 0; i < n - 1; ++i) {
        gaps.push_back(a[i + 1] - a[i] - 1);
    }
    std::sort(gaps.begin(), gaps.end());
    int ans = n;
    int used = n;
    int idx = 0;
    while (used > k) {
        used--;
        ans += gaps[idx++];
    }
    std::cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...