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>
#define ll long long
#define f first
#define sc second
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,idx,B[500005],le,ri,mid,ans;
ll A[500005];
vector <ll> v;
int main() {
cin>>n>>k;
for(ll i=1;i<=n;i++) {
cin>>A[i];
}
if(n==1) { cout<<1; return 0; }
sort(A+1,A+1+n);
for(ll i=1;i<n;i++) {
v.push_back(A[i+1]-A[i]-1);
}
sort(v.begin(),v.end());
g=v.size()-k+1;
for(ll i=v.size()-1;i>=max(f,g);i--) {
a+=v[i];
}
cout<<(A[n]+1)-A[1]-a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |