JAVA || 1-D DP || BINARY SEARCH || EASY TO UNDERSTAND
\nclass Solution {\n    public long maxTaxiEarnings(int max, int[][] rides) \n    {\n        int n=rides.length;\n        Arrays.sort(rides,(a,b)->a[0]!=b[0]?a[
```\nclass Solution {\n    public long maxTaxiEarnings(int max, int[][] rides) \n    {\n        int n=rides.length;\n        Arrays.sort(rides,(a,b)->a[0]!=b[0]?a[0]-b[0]:a[1]!=b[1]?a[1]-b[1]:a[2]-b[2]);\n        \n        \n        long dp[]=new long[n+1];\n        dp[n-1]=rides[n-1][1]-rides[n-1][0]+rides[n-1][2];\n        \n        for(int i=n-2;i>=0;i--)\n        {\n            int location=rides[i][1];\n            int pos=binarySearch(rides,location,i+1,n-1);\n            \n            long money=dp[pos]+rides[i][1]-rides[i][0]+rides[i][2];\n            dp[i]=Math.max(money,dp[i+1]);\n        }\n        \n        return dp[0];\n    }\n    \n    public int binarySearch(int rides[][],int target,int start,int end)\n    {\n        int ans=rides.length;\n        while(start<=end)\n        {\n            int mid=start+(end-start)/2;\n            \n            if(rides[mid][0]>=target)\n            {\n                ans=mid;\n                end=mid-1;\n            }\n            else\n            {\n                start=mid+1;\n            }\n        }\n        \n        return ans;\n    }\n    \n}\n```
['Dynamic Programming', 'Java']