Submission #1362751

#TimeUsernameProblemLanguageResultExecution timeMemory
1362751hoang5cngocthanhStove (JOI18_stove)C++20
100 / 100
27 ms2300 KiB
// Source: https://oj.uz/problem/view/JOI18_stove

#include <bits/stdc++.h>

constexpr int mo = 100005;

long long a[mo];

int main() {
    int n, k;
    std::cin >> n >> k;
    for (int i = 1 ; i <= n ; ++i) std::cin >> a[i];
    //den noi luc t[i], roi di luc t[i] + 1?
    //k que diem
    //moi lan bat -> 1 que
    //tong tg bat bep nho nht
    //std::sort(a + 1, a + n + 1);
    std::vector<long long> g;
    for (int i = 1 ; i < n ; ++i) {
        g.push_back(a[i + 1] - a[i] - 1);
    }
    std::sort(g.rbegin(), g.rend());
    long long ans = a[n] - a[1] + 1;
    for (int i =  0 ; i < k - 1 && i < g.size() ; ++i) {
        ans -= g[i];
    }
    std::cout << ans;
}
/*
3 2
1 
3
6
//2 que
bat diem o tg 1 -> tat o 4
bat diem o tg 6
-> tat o 7
-> total = (4 - 1) + (7 - 6) = 4:)
 */
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...