JAVA HEAP
\nclass Solution {\n    class pair{\n        int end;\n        long profit;\n        pair(int end,long profit){\n            this.end=end;\n            this.pro
```\nclass Solution {\n    class pair{\n        int end;\n        long profit;\n        pair(int end,long profit){\n            this.end=end;\n            this.profit=profit;\n        }\n    }\n    public long maxTaxiEarnings(int n, int[][] rides) {\n     \n        Arrays.sort(rides,(a,b)->{\n            return a[0]-b[0];\n        });\n       \n        long max=0;\n        \n        PriorityQueue<pair> pq=new PriorityQueue<>((a,b)->{\n            return a.end-b.end;\n        });\n        \n        \n        long ans=0;\n        for(int i=0;i<rides.length;i++){\n            while(pq.size()>0&&pq.peek().end<=rides[i][0]){\n                max=Math.max(max,pq.poll().profit);\n            }\n             pq.add(new pair(rides[i][1],rides[i][1]-rides[i][0]+rides[i][2]+max));\n            ans=Math.max(rides[i][1]-rides[i][0]+rides[i][2]+max,ans);\n        }\n        \n        return ans;\n\n        \n    }\n}\n```
[]