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 <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
int main () {
int n, k;
std::cin >> n >> k;
std::vector<int> t(n);
for (int &val: t)
std::cin >> val;
std::vector<int> helper(n - 1);
for (size_t i = 0; i != helper.size(); ++ i)
helper[i] = t[i + 1] - t[i];
std::sort(helper.begin(), helper.end(), std::greater<int>{});
unsigned int total_operation = t.back() - t.front() + 1;
assert(static_cast<size_t>(k) - 1 <= helper.size());
for (int i = 0; i < k - 1; ++ i)
total_operation -= helper[i] - 1;
std::cout << total_operation << 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... |