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