# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1278510 | gugug | Stove (JOI18_stove) | C11 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
vector<int> v;
int n, k;
cin >> n >> k;
int t1, t2;
int mx = -1e9, mn = 1e9;
for (int i = 0; i < n; i++) {
t2 = t1;
cin >> t1;
if (i) v.emplace_back(t1-t2-1);
mn = min(mn, t1);
mx = max(mx, t1);
}
sort(v.rbegin(), v.rend());
int ans = mx - mn + 1;
int idx = 0;
for (k--; k > 0; k--, idx++) {
ans -= v[idx];
}
cout << ans;
return 0;
}