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);
vector<int> b(n - 1);
for(int i = 0; i < n; ++i) {
cin >> a[i];
if(i) {
b[i - 1] = a[i] - a[i - 1] - 1;
}
}
sort(rbegin(b), rend(b));
int ans = a[n - 1] - a[0] + 1;
for(int i = 0; i < k - 1; ++i) {
ans -= b[i];
}
cout << ans << '\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... |