Skip to content

Commit 2416e18

Browse files
authored
Create 2402. Meeting Rooms III 1
1 parent 806b640 commit 2416e18

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

2402. Meeting Rooms III 1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution {
2+
public:
3+
int mostBooked(int n, vector<vector<int>>& meetings) {
4+
vector<int> booked(n, 0);
5+
priority_queue<int, vector<int>, greater<>> idle;
6+
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<>> busy;
7+
for (int i = 0; i < n; ++i) { idle.push(i); }
8+
ranges::sort(meetings, [](const auto& lhs, const auto& rhs) { return lhs[0] < rhs[0]; });
9+
for (const auto& m : meetings) {
10+
int start = m[0], end = m[1];
11+
while (!busy.empty() && busy.top().first <= start) {
12+
idle.push(busy.top().second);
13+
busy.pop();
14+
}
15+
if (!idle.empty()) {
16+
int room = idle.top();
17+
idle.pop();
18+
busy.push({end, room});
19+
++booked[room];
20+
} else {
21+
auto p = busy.top();
22+
busy.pop();
23+
p.first += end - start;
24+
busy.push(p);
25+
++booked[p.second];
26+
}
27+
}
28+
int res = -1, cur = -1;
29+
for (int i = 0; i < n; ++i) {
30+
if (booked[i] > cur) {
31+
cur = booked[i];
32+
res = i;
33+
}
34+
}
35+
return res;
36+
}
37+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy