# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1257425 | cheetah | Stove (JOI18_stove) | C++20 | 0 ms | 0 KiB |
#include <iostream>
#include <stdio.h>
#include <queue>
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=100005;
int n,k;
vector<int>pont(maxn),dist(maxn);
/*
bool check(int sure){
int k2=0;
int pot=0;
int i=1;
while(i<n){
pot+=pont[i]-pont[i-1];
if(pot>=sure){
pot=0;
i++;
k2++;
}/*
else if(){
}*/
}
}*/
int32_t main(){
int t=1;
//cin>>t;
while(t--){
int n,ans;
cin>>n>>k;
ans=n;
for(int i=0;i<n;i++){
cin>>pont[i];
}
for(int i=0;i<n-1;i++){
dist[i]=pont[i+1]-pont[i]-1;
}
sort(dist.begin(),dist.begin()+n-1);
for(int i=0;i<n-k;i++){
ans+=dist[i];
}
cout<<ans<<endl;
/*
int l=1,r=1000000005;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
r=mid;
}
else l=mid;
}
cout<<l<<endl;*/
}
}