-
Notifications
You must be signed in to change notification settings - Fork 481
/
1353.cpp
36 lines (32 loc) · 879 Bytes
/
1353.cpp
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
class Solution
{
public:
int maxEvents(vector<vector<int>>& events)
{
sort(events.begin(), events.end());
priority_queue<int, vector<int>, greater<int>> q;
int res = 0, index = 0, n = events.size();
int l = 1e5, r = 0;
for (auto& it : events)
{
l = min(it[0], l);
r = max(it[1], r);
}
for (int i = l; i <= r; i++)
{
while (index < n && events[index][0] <= i)
q.push(events[index++][1]);
if (q.empty() && index == n) return res;
while (!q.empty())
{
int pre = q.top(); q.pop();
if (i <= pre)
{
res++;
break;
}
}
}
return res;
}
};