C++| DP Memorization + Binary Search | Easy Code
Please Upvote :)\n\n\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n        sort(rides.begin(),rides.end());\n 
Please Upvote :)\n\n```\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n        sort(rides.begin(),rides.end());\n        vector<long long> dp(rides.size(),-1);\n        return fun(rides,dp,0);\n    }\n    long long fun(vector<vector<int>>& v,vector<long long>& dp, int i)\n    {\n        if(i>=v.size())\n            return 0;\n        \n        if(dp[i]!=-1)\n            return dp[i];\n        \n        long long t=fun(v,dp,i+1);\n        int next=search(v,v[i][1],i);\n        long long sum=v[i][2]+v[i][1]-v[i][0];\n        t=max(t,sum+fun(v,dp,next));\n        \n        return dp[i]=t;\n    }\n    int search(vector<vector<int>>& v,int val,int i)\n    {\n        int l=i+1;\n        int r=v.size()-1;\n        int res=v.size();\n        \n        while(l<=r)\n        {\n            int mid=(l+r)/2;\n            \n            if(v[mid][0]>=val)\n            {\n                res=mid;\n                r=mid-1;\n            }\n            else\n                l=mid+1;\n        }\n        return res;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C', 'Binary Tree', 'C++']