제출 #1017516

#제출 시각아이디문제언어결과실행 시간메모리
1017516vjudge1Stove (JOI18_stove)C++17
0 / 100
0 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Event { int time; bool is_start; Event(int t, bool start) : time(t), is_start(start) {} bool operator<(const Event& other) const { if (time == other.time) { return !is_start < !other.is_start; } return time < other.time; } }; int main() { int N, K; cin >> N >> K; vector<Event> events; for (int i = 0; i < N; ++i) { int T; cin >> T; events.emplace_back(T, true); events.emplace_back(T + 1, false); } sort(events.begin(), events.end()); int matches_used = 0; int current_time = 0; bool heater_on = false; int total_heating_time = 0; for (const auto& event : events) { int event_time = event.time; bool is_start = event.is_start; if (is_start) { if (!heater_on && matches_used < K) { heater_on = true; matches_used++; total_heating_time += (event_time - current_time); } } else { if (heater_on) { heater_on = false; total_heating_time += (event_time - current_time); } } current_time = event_time; } cout << total_heating_time << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...