#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NE r < tl || tr < l
#define double long double
#define int long long
using namespace std;
const int N=2e5+7;
const int mod=998244353;
const int inf=2e9;
void solve(){
int n, k;
cin >> n >> k;
int a[n+1]{};
vector<int>v;
for(int i=1; i <= n; i++){
cin >> a[i];
if(i>1)v.pb(a[i]-a[i-1]-1);
}
v.pb(0);
sort(all(v));
int ans=a[n]-a[1]+1;
for(int i=n-1; i > n-k; i--)ans -= v[i];
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin >> t;
while(t--)solve();
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... |