-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2402.cpp
More file actions
44 lines (35 loc) · 1.2 KB
/
Copy path2402.cpp
File metadata and controls
44 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Solution {
public:
int mostBooked(int n, vector<vector<int>> &meetings) const {
sort(begin(meetings), end(meetings));
typedef pair<long long, int> record;
priority_queue<record, vector<record>, greater<>> engaged;
priority_queue<int, vector<int>, greater<>> unused;
vector<int> count(n);
for (int i = 0; i < n; i++)
unused.push(i);
for (const auto meeting : meetings) {
const int s = meeting[0], e = meeting[1];
while (!engaged.empty() && engaged.top().first <= s) {
unused.push(engaged.top().second);
engaged.pop();
}
if (!unused.empty()) {
const int room = unused.top();
unused.pop();
count[room] += 1;
engaged.push({e, room});
} else {
const auto [end, room] = engaged.top();
engaged.pop();
count[room] += 1;
engaged.push({end + e - s, room});
}
}
int maxi = 0;
for (int i = 1; i < n; i++) {
if (count[i] > count[maxi]) maxi = i;
}
return maxi;
}
};