Java Solution | DP | TC : O(n * log(n))
\nclass Solution {\n    private static class Job {\n\t\tprivate int start;\n\t\tprivate int end;\n\t\tprivate int profit;\n\n\t\tpublic Job(int start, int end, 
```\nclass Solution {\n    private static class Job {\n\t\tprivate int start;\n\t\tprivate int end;\n\t\tprivate int profit;\n\n\t\tpublic Job(int start, int end, int profit) {\n\t\t\tthis.start = start;\n\t\t\tthis.end = end;\n\t\t\tthis.profit = profit;\n\t\t}\n\t}\n    \n    private int binarySearch(Job jobs[], int index) {\n\t\tint low = 0;\n\t\tint high = index - 1;\n\t\tint ans = -1;\n\t\twhile (low <= high) {\n\t\t\tint mid = low + (high - low) / 2;\n\t\t\tif (jobs[mid].end <= jobs[index].start) {\n\t\t\t\tans = mid;\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n    \n    public long maxTaxiEarnings(int n, int[][] rides) {\n\t\tJob jobs[] = new Job[rides.length];\n\t\tfor (int i = 0; i < rides.length; i++) {\n\t\t\tjobs[i] = new Job(rides[i][0], rides[i][1], rides[i][1] - rides[i][0] + rides[i][2]);\n\t\t}\n\t\tArrays.sort(jobs, (j1, j2) -> (j1.end - j2.end));\n\t\tlong[] dp = new long[rides.length];\n\t\tdp[0] = jobs[0].profit;\n\t\tfor (int i = 1; i < jobs.length; i++) {\n\t\t\tlong include = jobs[i].profit;\n\t\t\tint index = binarySearch(jobs, i);\n\t\t\tif (index != -1) {\n\t\t\t\tinclude += dp[index];\n\t\t\t}\n\t\t\tdp[i] = Math.max(include, dp[i - 1]);\n\t\t}\n\t\treturn dp[rides.length - 1];\n    }\n}\n```
['Sorting', 'Binary Tree', 'Java']