-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2054.cpp
More file actions
29 lines (29 loc) · 868 Bytes
/
2054.cpp
File metadata and controls
29 lines (29 loc) · 868 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
class Solution {
public:
int maxTwoEvents(vector<vector<int>>& events) {
set<int> st;
vector<vector<int>> ends;
for (auto& event : events) {
ends.push_back({event[1], event[2]});
}
sort(ends.begin(), ends.end());
int n = events.size();
int index = 0;
int maxValue = 0;
sort(events.begin(), events.end());
for (auto& event : events) {
int start = event[0];
int end = event[1];
int value = event[2];
while (index < n && ends[index][0] < start) {
st.insert(ends[index][1]);
index++;
}
maxValue = max(maxValue, value);
if (!st.empty()) {
maxValue = max(maxValue, value + *st.rbegin());
}
}
return maxValue;
}
};