C++ memoized solution using simple binary search
\n long long dp[1000005];\n    int nextpos(vector<vector<int>>& rides , int val , int idx )\n    {\n        int l=idx;\n        int h=rides.size()-1;\n        i
```\n long long dp[1000005];\n    int nextpos(vector<vector<int>>& rides , int val , int idx )\n    {\n        int l=idx;\n        int h=rides.size()-1;\n        int pos=h+1;\n        \n        while(l<=h)\n        {\n            int mid=(l+(h-l)/2);\n            \n            if(rides[mid][0]>=val)\n            {\n                pos=mid;\n                h=mid-1;\n            }\n            else\n            {\n                l=mid+1;\n            }\n        }\n        \n        return pos;\n    }\n    long long func( vector<vector<int>>& rides , int i , int n )\n    {\n        if(i>=n)\n        {\n            return 0;\n        }\n        \n        if(dp[i]!=-1)\n        {\n            return dp[i];\n        }\n        long long val1;\n        \n        val1=func(rides , i+1 , n);\n        \n        int idx=nextpos(rides , rides[i][1] , i);\n        \n       long long val2= (long long)(rides[i][1]-rides[i][0] + rides[i][2] )+ (long long)func(rides , idx , n );\n        \n        return dp[i]= max(val1 , val2);\n    }\n    long long maxTaxiEarnings(int m, vector<vector<int>>& rides) {\n        \n        memset(dp , -1  , sizeof(dp));\n        \n        \n        sort(rides.begin(),rides.end());\n        return func(rides , 0 , rides.size());\n        \n        \n        \n        \n        \n      \n    }\n```
['Dynamic Programming', 'Memoization', 'C', 'Binary Tree', 'C++']