Easy-understood Java solution with sort and postfix array
sort the events by the starting time\n2. create a postfix array to record the largest value after current starting time events[i][0]\n3. use binary search to fi
1. sort the events by the starting time\n2. create a postfix array to record the largest value after current starting time `events[i][0]`\n3. use binary search to find the first event that starting later than the one at current iteration \n\n```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        Arrays.sort(events, (a, b) -> a[0] - b[0]);\n        int onRight = 0, maxOne = 0, n = events.length;\n        int[] rightMax = new int[n+1];\n        for (int i = n - 1; i >= 0; i--) {\n            int start = events[i][0], end = events[i][1], val = events[i][2];\n            maxOne = Math.max(val, maxOne);\n            rightMax[i] = Math.max(rightMax[i+1], val);\n        }\n        int two = 0;\n        for (int i = 0; i < n; i++) {\n            int start = events[i][0], end = events[i][1], val = events[i][2];\n            int idx = binarySearch(end, events);\n            if (idx < n) {\n                two = Math.max(rightMax[idx] + val, two);\n            }\n        }\n        return Math.max(two, maxOne);\n    }\n    \n    public int binarySearch(int end, int[][] arr) {\n        int left = 0, right = arr.length;\n        while (left < right) {\n            int mid = left + (right - left) / 2;\n            if (arr[mid][0] > end) {\n                right = mid;\n            } else {\n                left = mid + 1;\n            }\n        }\n        return left;\n    }\n}\n```
['Binary Search Tree', 'Sorting', 'Java']