#include <bits/stdc++.h>
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
#define ll long long
#define pb push_back
#define ins insert
#define vec vector
using namespace std;
const ll N = 2e5 + 5;
const ll inf = 1e10;
void _(){
ll n, k; cin >> n >> k;
vec<ll>a(n); vec<ll>v;
for(ll i = 0; i < n; i++){
cin >> a[i];
if(!i) continue ;
v.pb(a[i] - a[i - 1] - 1);
}
ll ans = n;
sort(all(v));
for(ll i = 0; i < n - k; i++) ans += v[i];
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(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... |