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;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,k;
cin >> n >> k;
long long arr[n];
for(int i=0; i<n; i++) cin >> arr[i];
sort(arr,arr+n);
long long ans=arr[n-1]+1-arr[0];
long long dif[n-1];
for(int i=0; i<n; i++) dif[i]=arr[i+1]-arr[i]-1;
sort(dif,dif+n-1,greater<long long>());
for(int i=0; i<k-1; i++) if(dif[i]>0) ans-=dif[i];
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |