const int N = 1e5 + 7; typedef long long ll; typedef pair ii; class Solution { public: long long maxTaxiEarnings(int n, vector>& a) { vector f(n + 5, 0); vector graph[N]; for (auto x: a) { graph[x[1]].push_back(ii(x[0], x[1] - x[0] + x[2])); } for (int i = 1; i <= n; i++) { f[i] = f[i-1]; for (auto x: graph[i]) { f[i] = max(f[i], f[x.first] + x.second); } } return f[n]; } };