Submission #725735

#TimeUsernameProblemLanguageResultExecution timeMemory
725735hoainiemStove (JOI18_stove)C++14
100 / 100
26 ms2300 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define lc id<<1
#define rc id<<1^1
#define nmax 100008
using namespace std;
typedef pair<int, int> pii;
int n, k, ans, a[nmax];
vector<int>vt;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen("file.inp", "r", stdin);
//    freopen("file.out", "w", stdout);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ans = a[n] - a[1] + 1;
    for (int i = 2; i <= n; i++)
        vt.push_back(a[i] - a[i - 1] - 1);
    sort(vt.begin(), vt.end());
    while (--k){
        ans -= vt.back();
        vt.pop_back();
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...