#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); set<ll>st;
for(ll i = 0; i < n; i++){
cin >> a[i];
if(!i) continue ;
st.ins(a[i] - a[i - 1] - 1);
if(st.size() > n - k) st.erase(*st.rbegin());
}
ll ans = n;
for(ll i : st) ans += 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... |