One template for max profit from Events/Jobs selection questions
\nclass Solution:\n    def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int:        \n        rides.sort()\n        for job in rides:\n            j
```\nclass Solution:\n    def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int:        \n        rides.sort()\n        for job in rides:\n            job[2]+=job[1]-job[0]\n        \n        heap=[]\n        cur=ans=0\n        for start,e,p in rides:\n            \n            while heap and heap[0][0]<=start: \n                _,val=heappop(heap)\n                cur=max(cur,val)\n            heappush(heap,(e,cur+p))\n           \n            ans=max(ans,cur+p)\n            \n        return ans\n```\n\n[Maximum Profit in Job Scheduling ](https://leetcode.com/problems/maximum-profit-in-job-scheduling/)\nfor every job we store the max profit before the start of this job  + cur job profit (if its not overlapping) in a heap, so that we can use these values again for calculating profit during next job\n```\ndef jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int:\n        jobs= list(zip(startTime,endTime,profit))\n        jobs.sort()\n        print(jobs)\n        heap=[]\n        cur=ans=0\n        for start,e,p in jobs:           \n            while heap and heap[0][0]<=start: #checks for non overlapping\n                _,val=heappop(heap)\n                cur=max(cur,val)\n                \n            heappush(heap,(e,cur+p))          \n            ans=max(ans,cur+p)\n         \n        return ans        \n        \n```\n[2054. Two Best Non-Overlapping Events](https://leetcode.com/problems/two-best-non-overlapping-events/)\n```\nclass Solution:\n    def maxTwoEvents(self, events: List[List[int]]) -> int:\n        \n        events.sort()\n        res=0\n        cur=0\n        heap=[]\n        for left,r,v in events:\n            heappush(heap,(r,v))\n            \n            while heap and heap[0][0]<left:\n                R,val=heappop(heap)\n                cur=max(cur,val)\n            res=max(res,cur+v)\n            \n        return res\n```
['Heap (Priority Queue)', 'Python']