# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1228955 | adad | Stove (JOI18_stove) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define TASK ""
#define MASK(i) (1<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define int long long
#define fi first
#define se second
using namespace std;
const long long INF = 1e17, MOD = 1e9 + 7, maxN = 1e5 + 5;
int n, k, t[maxN];
vector <int> tg;
signed main() {
if (fopen(TASK ".INP", "r")) {
freopen(TASK ".INP", "r", stdin);
freopen(TASK ".OUT", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for(int i = 1; i <= n; i ++) cin >> t[i];
int ans = t[n] + 1 - t[i];
for(int i = 1; i <= n; i ++) tg.push_back(a[i] - a[i - 1] - 1);
sort(tg.rbegin(), tg.rend());
for(int i = 0; i < k and i < tg.size(); i ++) {
ans -= tg[i];
}
cout << ans;
}