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()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector <int> v(n);
for (auto& i : v)
cin >> i;
sort(v.begin(), v.end());
int interv_need = max(0, (int)v.size() - k);
priority_queue <int> pq;
for (int i = 1; i < (int)v.size(); i++)
pq.push(-(v[i] - v[i - 1] - 1));
int ans = v.size();
for (int _ = 0; _ < interv_need; _++) {
ans -= pq.top();
pq.pop();
}
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... |