Greedy solution, sorting
Sort the array on the basis of the difference between the threshold and actual energy.\n\nimport java.util.*;\nclass Solution {\n    public int minimumEffort(in
Sort the array on the basis of the difference between the threshold and actual energy.\n```\nimport java.util.*;\nclass Solution {\n    public int minimumEffort(int[][] tasks)\n    {\n        Arrays.sort(tasks, new Comparator<int[]>(){\n            @Override\n            public int compare(int[] a, int[] b)\n            {\n                return (b[1]-b[0])-(a[1]-a[0]);\n            }\n        });\n        int sum=0, max=0;\n        for(int i=0;i<tasks.length;i++)\n        {\n            max=Math.max(max, sum+tasks[i][1]);\n            sum+=tasks[i][0];\n        }\n        \n        return max;\n        \n    }\n}```
['Sorting', 'Java']