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;
#define int long long int
int32_t main () {
int n, k;
cin >> n >> k;
vector<int> v(n), res(n - 1);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 1; i < n; i++) {
res[i - 1] = v[i] - v[i - 1] - 1;
}
sort(res.begin(), res.end(), greater<int>());
int cost = 0;
for (int i = 0; i < k - 1; i++) {
cost += res[i];
}
cout << max(n, *max_element(v.begin(), v.end()) - cost) << 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... |