이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
struct Event {
int time;
bool is_arrival;
Event(int t, bool arrival) : time(t), is_arrival(arrival) {}
bool operator<(const Event& other) const {
if (time == other.time) {
return !is_arrival > !other.is_arrival;
}
return time > other.time;
}
};
int main() {
int N, K;
cin >> N >> K;
vector<Event> events;
for (int i = 0; i < N; ++i) {
int arrival, departure;
cin >> arrival >> departure;
events.emplace_back(arrival, true);
events.emplace_back(departure + 1, false);
}
sort(events.begin(), events.end());
priority_queue<int, vector<int>, greater<int>> pq;
long long total_heating_time = 0;
int current_time = 0;
for (const auto& event : events) {
int event_time = event.time;
bool is_arrival = event.is_arrival;
int interval = event_time - current_time;
if (!pq.empty()) {
total_heating_time += interval;
}
current_time = event_time;
if (is_arrival) {
if (K > 0) {
pq.push(event_time + 1);
K--;
}
} else {
if (!pq.empty()) {
pq.pop();
}
}
}
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... |