very simple java maxHeap O(nlogn)
Intuition\nYou can simulate the optimal run by ranking each task and going through them accordingly. Build up the required minimal energy for the simulation and
# Intuition\nYou can simulate the optimal run by ranking each task and going through them accordingly. Build up the required minimal energy for the simulation and that will be the answer. \n\n# Approach\nRank each task based on: energy required to start - actual energy cost\nUse a maxHeap to store these rankings and facilitate the simulation\nUse "ans" to keep track of all the energy we\'ve ever needed to add\nUse "currEnergy" to keep track of current energy as we simulate\nAdd minimum amount needed to keep going to "ans" if "currEnergy" is ever not enough\nGo through each task in maxHeap\nreturn "ans"\n\n# Complexity\n- Time complexity:\nO(nlogn), n = number of tasks all of which are added and removed from maxHeap\n\n- Space complexity:\nO(n), n = number of tasks to put in maxHeap\n\n# Code\n```\nclass Solution {\n    public int minimumEffort(int[][] tasks) \n    {\n        PriorityQueue<int[]> maxHeap = new PriorityQueue<>((a, b) -> \n        {\n            int diffA = a[1] - a[0];\n            int diffB = b[1] - b[0];\n            return Integer.compare(diffB, diffA); \n        });\n        for (int[] task : tasks) maxHeap.offer(task);\n        int ans = 0;\n        int currEnergy = 0;\n        while (!maxHeap.isEmpty())\n        {\n            int[] currTask = maxHeap.poll();\n            if (currTask[1] > currEnergy)\n            {\n                ans += (currTask[1] - currEnergy);\n                currEnergy = currTask[1];\n            }\n            currEnergy -= currTask[0];\n        }\n        return ans;\n    }\n}\n```
['Java']