This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: anony
* created: 02.09.2024 20:10:04
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> diff(n - 1);
for (int i = 1; i < n; i++) {
diff[i - 1] = a[i] - a[i - 1] - 1;
}
sort(diff.begin(), diff.end());
cout << accumulate(diff.begin(), diff.begin() + n - k, 0ll) + n;
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... |