#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, K; cin >> N >> K;
vector<int> t(N);
for (int i = 0; i < N; ++i) {
cin >> t[i];
}
vector<int> differences;
for (int i = 1; i < N; ++i) {
differences.push_back(t[i] - t[i - 1]);
}
int sum = t[N - 1] - t[0] + 1;
sort(differences.rbegin(), differences.rend());
for (int i = 0; i < K - 1; ++i) {
sum -= differences[i] - 1;
}
cout << sum << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |