-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1353.cpp
More file actions
33 lines (31 loc) · 749 Bytes
/
Copy path1353.cpp
File metadata and controls
33 lines (31 loc) · 749 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
28
29
30
31
32
33
#include "common.h"
class Solution {
public:
int maxEvents(vector<vector<int>> events) {
int ans = 0;
std::sort(events.begin(), events.end());
int max_day = 0;
for (auto& event : events) {
max_day = max(max_day, event[1]);
}
priority_queue<int, vector<int>, std::greater<>> pq;
for (int i = 1, j = 0; i <= max_day; ++i) {
while (j < events.size() && events[j].front() <= i) {
pq.push(events[j].back());
j += 1;
}
while (!pq.empty() && pq.top() < i) {
pq.pop();
}
if (!pq.empty()) {
ans += 1;
pq.pop();
}
}
return ans;
}
};
int main() {
Solution s;
cout << s.maxEvents({{1, 4}, {4, 4}, {2, 2}, {3, 4}, {1, 1}}) << endl;
}