#include<bits/stdc++.h>
using namespace std;
int a[1000100],b[1000100];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,k,mx=INT_MIN,mn=INT_MAX; cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
mx=max(mx,a[i]);
mn=min(mn,a[i]);
if(i>1){
b[i-1]=a[i]-a[i-1]-1;
}
}
sort(b+1,b+n+1,greater<int>());
int total=(mx+1-mn);
for(int i=1;i<=k-1;i++) total-=b[i];
cout<<total;
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... |