This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
int main() {
int n, k;
std::cin >> n >> k;
std::vector<ll> a(n);
for (auto &i : a) {
std::cin >> i;
}
std::vector<int> gaps;
for (int i = 0; i < n - 1; ++i) {
gaps.push_back(a[i + 1] - a[i] - 1);
}
std::sort(gaps.begin(), gaps.end());
int ans = n;
int used = n;
int idx = 0;
while (used > k) {
used--;
ans += gaps[idx++];
}
std::cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |