Submission #1290442

#TimeUsernameProblemLanguageResultExecution timeMemory
1290442mhaerStove (JOI18_stove)C++20
100 / 100
16 ms2372 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define vc vector
#define Fin(a) for (auto& i : a)
#define fih ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast") 
//#pragma GCC target("avx,avx2,fma")
using namespace std;

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

    int mm = input[n-1] - input[0] + 1;

    vc<int> bos;
    for (int i = 0;i < n-1;i++) {
        bos.pb(input[i+1] - input[i] - 1);
    }

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

    while (--k && bos.size() > 0) {
        mm -= bos.back();
        bos.pop_back();
    }

    cout << mm << "\n";
}
 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...