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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
int ans = v[n - 1] + 1 - v[0];
vector<int> improv;
for (int i = 1; i < n; ++i) {
improv.push_back(v[i] - v[i - 1] - 1);
}
sort(improv.rbegin(), improv.rend());
for (int i = 1; i < k; ++i) ans -= improv[i - 1];
cout << ans << "\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... |