| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1323438 | python_devopover | Stove (JOI18_stove) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
if(k >= n){
cout << n << endl;
return;
}
vector<int> pf(n);
for(int i = 0; i + 1 < n; i++){
pf[i] = a[i + 1] - (a[i] + 1);
}
sort(all(pf));
int ans = n;
for(int i = 0; i < n - k; i++) ans += pf[i];
cout << ans << endl;
return 0;
}
