제출 #1161905

#제출 시각아이디문제언어결과실행 시간메모리
1161905MinhKienStove (JOI18_stove)C++20
0 / 100
0 ms320 KiB
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 1e5 + 10;
int n, k, a[N];

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

    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    sort(a + 1, a + n + 1);
    for (int i = 1; i < n; ++i) {
        a[i] = a[i + 1] - a[i] - 2;
    }

    int ans = n * 2;
    sort(a + 1, a + n);
    for (int i = 1; i <= n - k; ++i) {
        ans += a[i];
    }

    cout << ans << "\n";

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