#include <bits/stdc++.h>
using namespace std;
bool bigger(long long a, long long b){
return a>b;
}
int main(){
long long N, K; cin>>N>>K;
long long T[N];
for(long long i=0; i<N; i++){
cin>>T[i];
}
long long differences[N-1];
for(long long i=0; i<N-1; i++){
differences[i]=T[i+1]-T[i]-1;
}
sort(differences,differences+N-1,bigger);
long long ans=T[N-1];
for(long long i=0; i<K-1; i++){
ans-=differences[i];
}
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... |