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> t(n);
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
vector<int> v;
int p = t[0] + 1;
for (int i = 1; i < n; ++i) {
if (t[i] != p) v.push_back(t[i] - p);
p = t[i] + 1;
}
sort(v.rbegin(), v.rend());
int m = min((int) v.size(), k - 1);
int ans = t[n - 1] + 1 - t[0];
for (int i = 0; i < m; ++i) {
ans -= v[i];
}
cout << ans << endl;
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... |