Java Concise with Explanation
\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        // -sort the events by start time\n        // -rely on the fact that for any event ev
```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        // -sort the events by start time\n        // -rely on the fact that for any event events[i], all events after events[i] start at a time\n        // after events[i] and so do not overlap with any previous events not overlapping with events[i].\n        // hence, we can maintain a PQ of end times for events to keep track of which events don\'t overlap with\n        // the current event,\n        // and maintain a maximum-valued previous event to combine with curr events[i]\n        // answer will either be using two or one event sine value is nonnegative\n        \n        // sort events by start time\n        Arrays.sort(events, (event1, event2) -> Integer.compare(event1[0], event2[0]));\n        \n        // maintaining the end times of previous events to use for checking overlap\n        PriorityQueue<int[]> endTimes = new PriorityQueue<>((event1, event2) -> Integer.compare(event1[1], event2[1]));\n        \n        // finally, max-valued event we\'ve seen thus far\n        int maxValuedEvent = 0;\n        int ans = 0;\n        \n        // now start the iterative process\n        for (int[] event : events) {\n            while (!endTimes.isEmpty() && endTimes.peek()[1] < event[0]) {\n                maxValuedEvent = Math.max(maxValuedEvent, endTimes.poll()[2]);\n            }\n            ans = Math.max(ans, maxValuedEvent + event[2]);\n            endTimes.offer(event);\n        }\n        return ans;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']