This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k; cin >> n >> k;
vector<int> a (n);
for (int &x : a) cin >> x;
vector<int> diff (n-1);
for (int i = 0; i < n-1; ++i) {
if (a[i+1] == a[i]+1) continue;
diff[i] = a[i+1] - a[i] - 1;
}
sort(diff.begin(), diff.end());
int ans = 0;
for (int i = 0; i < n-k; ++i) {
ans += diff[i];
}
cout << ans+n << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |