Submission #1093790

#TimeUsernameProblemLanguageResultExecution timeMemory
1093790julianStove (JOI18_stove)C++98
100 / 100
42 ms2956 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...