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 <iostream>
#include <vector>
#include <algorithm>
int main() {
long N, K;
std::cin >> N >> K;
std::vector<long> T(N);
for (long i = 0; i < N; i++) {
std::cin >> T[i];
}
std::sort(T.begin(), T.end());
std::vector<long> diffs(N - 1);
for (long i = 0; i < N - 1; i++) {
diffs[i] = T[i + 1] - T[i] - 1;
}
std::sort(diffs.begin(), diffs.end(), std::greater<>());
long cost = T[N - 1] - T[0] + 1;
for (long k = 0; k < K - 1; k++) {
if (diffs[k] > 0)
cost -= diffs[k];
}
std::cout << cost << std::endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |