-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1942.cpp
More file actions
27 lines (23 loc) · 824 Bytes
/
Copy path1942.cpp
File metadata and controls
27 lines (23 loc) · 824 Bytes
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
class Solution {
public:
int smallestChair(const vector<vector<int>> ×, int targetFriend) const {
static tuple<int, bool, int> timeline[20002];
const int n = size(times);
priority_queue<int> seats;
for (int i = 0; i < n; i++) {
timeline[i * 2] = {times[i][0], true, i};
timeline[i * 2 + 1] = {times[i][1], false, i};
seats.push(-i);
}
sort(timeline, timeline + n * 2);
static int assign[10001];
for (const auto [time, sit, person] : span(timeline, timeline + n * 2)) {
if (person == targetFriend) return -seats.top();
if (sit)
assign[person] = seats.top(), seats.pop();
else
seats.push(assign[person]);
}
return -1;
}
};