#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |