Greedy + Binary search
Intuition\nso the minimum must lie between the maximum minimum energy required and the sum of all minimum energy required for all tasks. \ntricky part is to sor
# Intuition\nso the minimum must lie between the maximum minimum energy required and the sum of all minimum energy required for all tasks. \ntricky part is to sort them in a way that the higher minimum energy required task is done first.\nhence we sort by difference.\n\n# Approach\nGreedy + Binary search\n\n# Code\n```\nclass Solution {\npublic:\n    bool check(int m, vector<vector<int>>&tasks){\n        int rem=m;\n        for(int i=0;i<tasks.size();i++){\n            if(rem>=tasks[i][1]) rem-=tasks[i][0];\n            else return false;\n        }\n        return true;\n        \n    }\n    int minimumEffort(vector<vector<int>>& tasks) {\n        sort(tasks.begin(),tasks.end(), [&](vector<int>a, vector<int>b){\n           return a[1]-a[0]>b[1]-b[0];\n        });\n        int maxi= INT_MIN;\n        for(int i=0;i<tasks.size();i++) maxi=max(maxi,tasks[i][1]);\n        int low=maxi;\n        int high=0;\n        int ans;\n        for(int i=0;i<tasks.size();i++) high+= tasks[i][1];\n        while(low<=high){\n             int mid=(low+high)/2;\n            if(check(mid,tasks)) {\n                ans=mid;\n                high=mid-1;\n            }\n            else low=mid+1;\n        }\n        return ans;\n       \n    }\n\n};\n```
['Binary Search', 'Greedy', 'C++']