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 <queue>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int a [N];
int main () {
ios::sync_with_stdio(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
sort (a, a + n);
int res = a[n - 1] - a[0] + 1;
--k;
vector<int> dis;
int rem = 0;
priority_queue<int, vector<int>, greater<int> > pq;
for (int i = 1; i < n; i++) {
pq.push(a[i] - a[i - 1] - 1);
if ( (int) pq.size() > k) pq.pop();
}
while (!pq.empty()) {
rem += pq.top();
pq.pop();
}
cout << res - rem << '\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... |