JAVA
This question revolves around finding minimum cost to complete all the task\nWe we will use the idea of sorting according to difference of Minimum - actual\nin 
This question revolves around finding minimum cost to complete all the task\nWe we will use the idea of sorting according to difference of ```Minimum - actual```\nin Descending order. \nThis will help us in setting the initial value for energy required in such \na way that left over after using the energy can be used for further demands and if further demand\nis not  fulfilled, update the ```cur``` and ```initial``` requirement so that we can reach minimum\nrequirement of task.\nrepeat above process to finish all task....\nTime Complexity : ```O(NlogN)```\nUpvote if you like my explanation....!!!!\n\n```class Solution {\n    public int minimumEffort(int[][] tasks) {\n        Arrays.sort(tasks,new Comparator<int[]>(){\n                    public int compare(int[] a,int[] b){\n                        if((a[1] - a[0]) > (b[1] - b[0]))\n                            return -1;\n                        else return 1;\n                    }\n                    });\n        int initial = tasks[0][1];\n        int cur = initial;\n        for(int i[] : tasks){\n            if(cur >= i[1]){\n                cur -= i[0];\n            }\n            else{\n                initial = initial + i[1] - cur;\n                cur = i[1]-i[0];\n            }\n        } \n        return initial;\n        \n    }\n}
['Java']