C# Top Down
\npublic class Solution {\n    public long MaxTaxiEarnings(int n, int[][] rides) {\n        Array.Sort(rides, (x,y) => x[0].CompareTo(y[0]));\n        return ma
```\npublic class Solution {\n    public long MaxTaxiEarnings(int n, int[][] rides) {\n        Array.Sort(rides, (x,y) => x[0].CompareTo(y[0]));\n        return max(0, rides, new long[rides.Length]);\n    }\n    \n    private long max(int i, int[][] r, long[] memo)\n    {\n        if(i >= r.Length) return 0;\n        if(memo[i] > 0) return memo[i];\n        \n        long profit = r[i][1]-r[i][0]+r[i][2];\n        long sum = Math.Max(max(i+1, r, memo), profit);\n        int next = search(i, r);        \n        sum = Math.Max(sum, max(next, r, memo) + profit);\n        \n        memo[i] = sum;\n        return memo[i];\n    }\n    \n    private int search(int i, int[][] r)\n    {\n        int lo = i, hi = r.Length;\n        while(lo < hi)\n        {\n            int mid = lo+(hi-lo)/2;\n            if(r[i][1] <= r[mid][0])\n                hi = mid;\n            else\n                lo = mid+1;\n        }\n        return lo;\n    }\n}\n```
[]