[C++ DP]
\n\nclass Solution {\npublic:\n    static bool fun(vector<int> &a, vector<int> &b){\n        return a[1] > b[1];\n    }\n    long long maxTaxiEarnings(int n, ve
```\n\nclass Solution {\npublic:\n    static bool fun(vector<int> &a, vector<int> &b){\n        return a[1] > b[1];\n    }\n    long long maxTaxiEarnings(int n, vector<vector<int>>& r) {\n        sort(r.begin(), r.end(), fun);\n        vector<long long> dp(n+2, 0);\n        long long ans= 0;\n        int j= 0;\n        for(int i= n;i>= 1; i--)\n        {\n            ans= max(ans, dp[i]);\n            while(j!= r.size()&&r[j][1]==i)\n            {\n                dp[r[j][0]]= max(r[j][1]-r[j][0]+r[j][2]+ans, dp[r[j][0]]);\n                j++;\n            }\n        }\n        return ans;\n    }\n};\n```
[]