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 n, k, arr[100010], ans;
priority_queue<int> pq;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
k--;
for(int i=0; i<n; i++) {
cin >> arr[i];
}
sort(arr, arr+n);
for(int i=1; i<n; i++) {
pq.push(arr[i]-arr[i-1]-1);
}
ans = arr[n-1] - arr[0]+1;
while(k--) {
ans -= pq.top();
pq.pop();
}
cout << ans;
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... |