// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(sth) sth.begin(), sth.end()
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e9 + 7;
#define int ll
void solve(){
int n, k;cin >> n >> k;
int ans = 0;
vector<int> a(n);
vector<int> b(n-1);
for(int i=0; i<n; ++i){
cin >> a[i];
// ans += a[i];
}
ans += a[n-1] - a[0] + 1;
if(k >= n){
cout << n << '\n';
return;
}
for(int i=0; i<n-1; ++i){
b[i] = a[i+1] - a[i] - 1;
}
sort(alle(b), [](int a, int b){
return a > b;
});
for(int i=0; i<k-1; ++i){
ans -= b[i];
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |