Submission #1290551

#TimeUsernameProblemLanguageResultExecution timeMemory
1290551ctfoxStove (JOI18_stove)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    int a, b;
    if (!(std::cin >> a >> b)) return 0;
    std::vector<long long> c(a);
    for (int i = 0; i < a; ++i) std::cin >> c[i];
    if (a <= 1) {
        std::cout << 0 << '\n';
        return 0;
    }
    std::vector<long long> d;
    d.reserve(a-1);
    for (int i = 0; i + 1 < a; ++i) d.push_back(c[i+1] - c[i]);
    long long e = c.back() - c.front();
    if (b >= a) {
        std::cout << 0 << '\n';
        return 0;
    }
    std::sort(d.begin(), d.end(), std::greater<long long>());
    long long f = 0;
    for (int i = 0; i < b-1 && i < (int)d.size(); ++i) f += d[i];
    long long g = e - f;
    if (g < 0) g = 0;
    std::cout << g << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...