Greedy approach. Sorted using comparator.C++
Intuition\nThe more you energyyou save from the current task can be used later on.Simple greedy approach\n\n# Approach\nUsed a comparator to sort the tasks vect
# Intuition\nThe more you energyyou save from the current task can be used later on.Simple greedy approach\n\n# Approach\nUsed a comparator to sort the tasks vector according to the differnce of mininum and actual energy required\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\nstatic bool cmp(vector<int>&a,vector<int>&b){\n    return (a[1]-a[0])>(b[1]-b[0]);\n}\n    int minimumEffort(vector<vector<int>>& tasks) {\n        sort(tasks.begin(),tasks.end(),cmp);\n        int initial=0,ans=0;\n        for(int i=0;i<tasks.size();i++){\n            if(tasks[i][1]>initial){\n                ans+=tasks[i][1]-initial;\n                initial=tasks[i][1];\n            }\n            initial-=tasks[i][0];\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'Sorting', 'C++']