#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<long long> T(N);
for (int i = 0; i < N; i++) cin >> T[i];
if (K >= N) { // 1 match per guest → 1 time unit each
cout << N << "\n";
return 0;
}
vector<long long> gaps;
for (int i = 0; i < N - 1; i++) {
gaps.push_back(T[i+1] - (T[i] + 1));
}
sort(gaps.begin(), gaps.end(), greater<long long>());
long long total_span = (T[N-1] + 1) - T[0];
long long subtract = 0;
for (int i = 0; i < K - 1; i++) {
if (i < (int)gaps.size()) subtract += gaps[i];
}
cout << total_span - subtract << "\n";
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... |