GREEDY || Custom Sorting || Explained
Complexity\n- Time complexity: O(n*log(n)) \n\n- Space complexity: O(1) \n\n# Code\n\nclass Solution {\npublic:\n    int minimumEffort(vector<vector<int>>& task
# Complexity\n- Time complexity: $$O(n*log(n))$$ \n\n- Space complexity: $$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int minimumEffort(vector<vector<int>>& tasks) {\n        //sort in decsending order of difference between minimum and actual energy\n        sort(tasks.begin(),tasks.end(), [](vector<int>& a, vector<int>& b) {\n            return a[1]-a[0] > b[1]-b[0];\n        });\n\n        int ans = 0;\n        for(auto it : tasks) {\n            ans += it[0]; //minimum energy needed is the sum of actual energy of all tasks\n        }\n\n        int curr = ans;\n        for(auto it : tasks) {\n           if(curr < it[1]) { //if current energy if lesser than the minimum energy for this task\n             ans += (it[1]-curr); //increment initial energy by the difference\n             curr = it[1]; //increment current energy to become equal to minimum required energy\n           }\n         curr -= it[0]; //decrement current energy by the amount needed to perform current task\n        }\n     return ans;\n    }\n};\n```
['Greedy', 'Sorting', 'C++']