Maximum Earnings From Taxi | C++ | DP | NLogN
Same as Maximum Profit in Job Scheduling\n\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& A) {\n        sort(begin(A), en
Same as [Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/)\n```\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& A) {\n        sort(begin(A), end(A), [&](auto& a, auto& b){\n            return a[1] < b[1];\n        });\n        \n        int m = A.size();\n        long dp[m];\n        dp[0] = A[0][1] - A[0][0] + A[0][2];\n        \n        auto BS = [&](int i){\n            int l = 0, r = i - 1, ans = -1;\n            while(l <= r){\n                int m = l + (r - l) / 2;\n                if(A[m][1] <= A[i][0]){\n                    ans = m;\n                    l = m + 1;\n                }\n                else r = m - 1;\n            }\n            return ans;\n        };\n        \n        for(int i = 1; i < m; i++){\n            long pick = A[i][1] - A[i][0] + A[i][2];\n            int idx = BS(i);\n            if(idx != -1) pick += dp[idx];\n            long discard = dp[i - 1];\n            dp[i] = max(pick, discard);\n        }\n        \n        return dp[m - 1];\n    }\n};\n```
['Dynamic Programming']