[Java/C++/Python] DP solution
Explanation\nSort A, solve it like Knapsack dp.\n\n\n# Complexity\nTime O(n + klogk), k = A.length\nSpace O(n)\n\n\nJava\njava\n    public long maxTaxiEarnings(
# **Explanation**\nSort `A`, solve it like Knapsack dp.\n<br>\n\n# **Complexity**\nTime `O(n + klogk), k = A.length`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n    public long maxTaxiEarnings(int n, int[][] A) {\n        Arrays.sort(A, (a, b) -> a[0] - b[0]);\n        long[] dp = new long[n + 1];\n        int j = 0;\n        for(int i = 1; i <= n; ++i) {\n            dp[i] = Math.max(dp[i], dp[i - 1]);\n            while (j < A.length && A[j][0] == i) {\n                dp[A[j][1]] = Math.max(dp[A[j][1]], dp[i] + A[j][1] - A[j][0] + A[j][2]);\n                ++j;\n            }\n        }\n        return dp[n];\n    }\n```\n**C++**\n```cpp\n    long long maxTaxiEarnings(int n, vector<vector<int>>& A) {\n        sort(A.begin(), A.end());\n        vector<long long> dp(n+1);\n        int j = 0;\n        for(int i = 1; i <= n; ++i) {\n            dp[i] = max(dp[i], dp[i - 1]);\n            while (j < A.size() && A[j][0] == i)\n                dp[A[j++][1]] = max(dp[A[j][1]], dp[i] + A[j][1] - A[j][0] + A[j][2]);\n        }\n        return dp[n];\n    }\n```\n\n**Python**\n```py\n    def maxTaxiEarnings(self, n, A):\n        dp = [0] * (n + 1)\n        A.sort()\n        for i in xrange(n - 1, -1, -1):\n            dp[i] = dp[i + 1]\n            while A and i == A[-1][0]:\n                s, e, t = A.pop()\n                dp[i] = max(dp[i], dp[e] + e - s + t)\n        return dp[0]\n```\n
[]