[C++]Simple C++ Code
\n# If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n    i
\n# **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n    int BinarySearch(int &val, int &e, int &s, vector<vector<int>>& rides)\n    {\n        int end = e-1, start = s+1, ans = e;\n        while(start <= end)\n        {\n            int mid = start + (end - start)/2;\n            if(rides[mid][0] >= val)\n            {\n                ans = mid;\n                end = mid-1;\n            }\n            else\n                start = mid+1;\n        }\n        return ans;\n    }\n    long long dfs(vector<long long> &dp, vector<vector<int>>& rides, int i, int &n)\n    {\n        if(i >= n) return 0;\n        if(dp[i] != -1) \n            return dp[i];\n        int val = BinarySearch(rides[i][1], n, i, rides);\n        long long price = rides[i][1]-rides[i][0]+rides[i][2];\n        return dp[i] = max(dfs(dp, rides, i+1, n),price + dfs(dp, rides, val, n));\n    }\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n        int m = rides.size();\n        sort(rides.begin(), rides.end());\n        vector<long long> dp(m, -1);\n        return dfs(dp, rides, 0, m);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C', 'Binary Tree']