2054. Two Best Non-Overlapping Events
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nfrom bisect import bisect_right\n\nclass Solution:\n    def maxTwoEvents(self, events: List[List[int]]) -> int:\n        # Sort events by end time\n        events.sort(key=lambda x: x[1])\n        \n        # Store the maximum value at each step\n        max_value = 0\n        max_sum = 0\n        \n        # To store end times and cumulative max values\n        end_times = []\n        cumulative_max = []\n        \n        for start, end, value in events:\n            # Find the index of the last event that ends before the current event\'s start\n            idx = bisect_right(end_times, start - 1) - 1\n            \n            # Calculate max sum with the current event\n            if idx >= 0:\n                max_sum = max(max_sum, value + cumulative_max[idx])\n            else:\n                max_sum = max(max_sum, value)\n            \n            # Update running maximum value and cumulative lists\n            max_value = max(max_value, value)\n            end_times.append(end)\n            cumulative_max.append(max_value)\n        \n        return max_sum\n\n```
['Python3']