# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127239 | watahata | Stove (JOI18_stove) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
#define ll __int128
#define endl '\n'
#define fi first
#define se second
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define vini(x, y) for (int i = 0; i < y; i++) cin >> x[i];
#define gcd(a, b) __gcd(a, b)
#define lcm(a,b) (a * (b / gcd(a,b)))
using namespace std;
#ifndef ONLINE_JUDGE
#include <C:/Users/cleme/OneDrive/Desktop/debug.h>
#else
#define debug(...) 42
#endif
void solve()
{
int a, b; cin >> a >> b;
vector<int> arr(a); vini(arr, a);
int now = arr.back()-arr[0]+1;
vector<int> place;
for (int i = 0; i < a-1; i++)
{
place.pb(arr[i+1]-arr[i]-1);
}
sort(all(place), greater<int>());
for (int i = 0; i < b-1; i++)
{
now -= place[i];
}
cout << now << endl;
}
int32_t main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int a = 1;
// cin >> a;
for (int i = 0; i < a; i++) solve();
}