#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> V;
for(int i = 2; i <= n; i++) {
V.push_back(a[i] - a[i - 1]);
}
sort(V.begin(), V.end());
if(k >= n) {
cout << n;
return 0;
}
if(k == 1) {
cout << a[n] + 1 - a[1];
return 0;
}
int ans = 0;
for(int i = 0; i < n - k; i++) {
ans += V[i];
}
cout << ans + k;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |