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;
const int N = 5 * 1e3 + 1;
const int inf = 1e9 + 7;
signed main() {
int n, k;
cin >> n >> k;
vector <int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
vector <int> vv;
int dist = 0;
for (int i = 1; i < n; i++) {
vv.push_back(v[i] - v[i - 1]);
}
sort(vv.begin(), vv.end());
for (int i = 0; i < n - k; i++) dist += vv[i];
dist += k;
cout << dist << '\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... |