Sort + Min Heap
We sort events by the start date, and then go left to right. We also track end times and values in a min heap.\n\nWhen we process an event, we remove past event
We sort events by the start date, and then go left to right. We also track end times and values in a min heap.\n\nWhen we process an event, we remove past events from the min heap, and track the `max_val` so far.\n\n**C++**\nPriority queue is a max heap by default; we can just store end times as negative instead of providing a custom comparator.\n\n```cpp\nint maxTwoEvents(vector<vector<int>>& events) {\n    int res = 0, max_val = 0;\n    priority_queue<pair<int, int>> pq;\n    sort(begin(events), end(events));\n    for (auto &e : events) {\n        for(; !pq.empty() && -pq.top().first < e[0]; pq.pop())\n            max_val = max(max_val, pq.top().second);\n        res = max(res, max_val + e[2]);\n        pq.push({-e[1], e[2]});\n    }\n    return res;\n}\n```
['C']