#include <bits/stdc++.h>
using namespace std;
#define sigma int
sigma main() {
sigma N, K;
cin >> N >> K;
sigma T[N];
for (sigma i = 0; i < N; i++) cin >> T[i];
sigma ans = T[N-1] - T[0] + 1;
priority_queue<sigma> pq;
for (sigma i = 1; i < N; i++) pq.push(T[i] - T[i-1] - 1);
for (sigma i = 1; i < K; i++) {
ans -= pq.top();
pq.pop();}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |