Submission #1290553

#TimeUsernameProblemLanguageResultExecution timeMemory
1290553ctfoxStove (JOI18_stove)C++20
0 / 100
1 ms332 KiB
#include <iostream> #include <vector> #include <algorithm> int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); int N, K; if (!(std::cin >> N >> K)) return 0; std::vector<long long> T(N); for (int i = 0; i < N; ++i) std::cin >> T[i]; if (N <= 1) { std::cout << 0 << '\n'; return 0; } std::vector<long long> gaps; gaps.reserve(N - 1); for (int i = 0; i + 1 < N; ++i) gaps.push_back(T[i+1] - T[i]); long long total = T.back() - T.front(); if (K >= N) { std::cout << 0 << '\n'; return 0; } std::sort(gaps.begin(), gaps.end(), std::greater<long long>()); long long cut = 0; int take = std::max(0, K - 1); for (int i = 0; i < take && i < (int)gaps.size(); ++i) cut += gaps[i]; long long ans = total - cut; if (ans < 0) ans = 0; std::cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...