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