C++ | DP | O(n + rides.size())
\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n             vector<long long int>dp(n+1,0);\n             vect
```\nclass Solution {\npublic:\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n             vector<long long int>dp(n+1,0);\n             vector<vector<int>>end(n+1);\n             int size=rides.size();\n             for(int i=0;i<size;i++)\n                 end[rides[i][1]].push_back(i);\n             for(int i=1;i<=n;i++){\n                 dp[i]=dp[i-1];\n                 if(end[i].size()==0)continue;\n                 for(auto e:end[i]){\n                     dp[i]=max(dp[i],rides[e][1]-rides[e][0]+rides[e][2]+dp[rides[e][0]]);\n                 }\n             } \n        return dp[n];\n    }\n};\n```
[]