easy to understand
```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        int dp[][] = new int[events.length][3],output = 0;\n        for(int row[]:dp) Arra
```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        int dp[][] = new int[events.length][3],output = 0;\n        for(int row[]:dp) Arrays.fill(row,-1);\n        Arrays.sort(events,(a,b)->(a[0]-b[0]));\n        int out =  find(dp,events,0,2);\n        for(int row[]:events) output = Math.max(output,row[2]);\n        return Math.max(out,output);\n    }\n    public int find(int dp[][],int events[][],int n,int count){\n        if(count==0) return 0;\n        if(n>=events.length||n==-1) return Integer.MIN_VALUE;\n        if(dp[n][count]!=-1) return dp[n][count];\n        int op = find(dp,events,n+1,count);\n        int upper = bisearch(events,events[n][1]);\n        int yo = events[n][2]+find(dp,events,upper,count-1);\n        return dp[n][count] = Math.max(op,yo);\n    }\n    public int bisearch(int events[][],int val){\n        int top=0,bot=events.length-1;\n        while(top<bot){\n            int mid = (bot-top)/2+top;\n            if(events[mid][0]>val) bot=mid;\n            else top = mid+1;\n        }\n        if(events[bot][0]<=val) return -1;\n        return bot;\n    }\n}\n//similar question \n//2555. Maximize Win From Two Segments\n//prob. same code\n//answer mentioned in comment in java\n//https://leetcode.com/problems/maximize-win-from-two-segments/discuss/3144297/C%2B%2B-or-or-DP%2BBS-or-or-Memoization-or-or-Well-Explained-Code
['Dynamic Programming', 'Binary Tree', 'Java']