#include "bits/stdc++.h"
using namespace std;
#define int int64_t
void solve() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vector<int> dif;
for (int i = 2; i <= n; ++i) {
dif.push_back(a[i] - a[i - 1] - 1);
}
int tot = a[n] - a[1] + 1;
sort (dif.begin(), dif.end(), greater<int>());
int take = 0;
for (int i = 0; i < k - 1; ++i) {
take += dif[i];
}
int ans = tot - take;
cout << ans << '\n';
}
signed main() {
int t = 1;
// cin >> t;
for (int cs = 1; cs <= t; ++cs) {
solve();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |