Submission #1200892

#TimeUsernameProblemLanguageResultExecution timeMemory
1200892kazukihoshino8703Stove (JOI18_stove)C++20
100 / 100
12 ms1864 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<int, int>

const int mn = 1e5+5;
int n, m, a[mn];
int ed[mn];

void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n - 1; i++){
        ed[i] = a[i + 1] - a[i];
    }
    sort(ed + 1, ed + n);
    int res = m;
    for(int i = 1; i <= n - m; i++){
        res += ed[i];
    }
    cout << res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...