#include<bits/stdc++.h>
#define ll long long
using namespace std;
void uwu(){
ll n,k;
cin>>n>>k;
ll a[n+8];
for(ll i=0; i<n; i++) cin>>a[i];
vector<ll> x;
for(ll i=n-1; i>=1; i--){
x.push_back(a[i]-a[i-1]);
}
ll ans=a[n-1]-a[0];
sort(x.begin(), x.end());
for(ll i=n-2; i>=n-k; i--){
ans-=x[i];
}
ans+=k;
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll t=1;
//cin>>t;
while(t--){
uwu();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |