이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |