Java, BinarySearch, O(mlogm)
\n    public long maxTaxiEarnings(int n, int[][] rides) {\n        Arrays.sort(rides, (r1, r2) -> r1[1] - r2[1]);\n        \n        List<long[]> preEnd = new A
```\n    public long maxTaxiEarnings(int n, int[][] rides) {\n        Arrays.sort(rides, (r1, r2) -> r1[1] - r2[1]);\n        \n        List<long[]> preEnd = new ArrayList<>();\n        preEnd.add(new long[]{0, 0});\n        long ret = 0;\n        for(int[] ride : rides) {\n            long earn = ride[1] - ride[0] + ride[2];\n            earn += bs(preEnd, ride[0]);\n            ret = Math.max(ret, earn);\n            if(earn > preEnd.get(preEnd.size() - 1)[1]) {\n                preEnd.add(new long[]{ride[1], earn});\n            }\n        }\n        return ret;\n    }\n    \n    private long bs(List<long[]> pre, int limit) {\n        int lo = 0;\n        int hi = pre.size() - 1;\n        int mid;\n        while(lo <= hi) {\n            mid = lo + ((hi - lo) >> 1);\n            if(pre.get(mid)[0] <= limit) lo = mid + 1;\n            else hi = mid - 1;\n        }\n        return pre.get(lo - 1)[1];\n    }\n```
[]