#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
K--;
priority_queue<ll> gap;
ll pr = -1;
ll tot;
FOR(i, N) {
ll t;
cin >> t;
if (pr != -1) gap.push(t-pr-1);
if (i == 0) tot = -t;
if (i == N-1) tot += t+1;
pr = t;
}
while(gap.size() && K) {
K--;
tot -= gap.top();
gap.pop();
}
cout << tot;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |