Submission #783777

#TimeUsernameProblemLanguageResultExecution timeMemory
783777BoasStove (JOI18_stove)C++17
100 / 100
37 ms960 KiB
#include <bits/stdc++.h> using namespace std; #define loop(x) for (int i = 0; i < x; i++) int main() { int N, K; cin >> N >> K; // vector<int> T(N); vector<int> gaps; int prevT = -1; int matchesUsed = 0; int burnTime = N; loop(N) { int t; cin >> t; if (prevT == -1 || t - prevT > 1) { matchesUsed++; if (prevT != -1) { gaps.push_back(-1 * (t - prevT - 1)); // gapSize } } prevT = t; // cin >> T[i]; } sort(gaps.begin(), gaps.end()); int inx = gaps.size() - 1; while (matchesUsed > K) { int g = -gaps[inx]; matchesUsed--; burnTime += g; inx--; } cout << burnTime << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...