Beats 99% CPP Solution Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minimumEffort(vector<vector<int>>& tasks) {\n        vector<pair<int,int>> a;\n        for(int i=0;i<tasks.size();i++){\n            a.push_back({tasks[i][1]-tasks[i][0],i});\n        }\n        sort(a.begin(),a.end());\n        reverse(a.begin(),a.end());\n        int ans = 0,tot = 0;;\n        for(int i=0;i<a.size();i++){\n            int j = a[i].second;\n            int consume = tasks[j][0];\n            int need = tasks[j][1];\n            if(ans<need){\n                tot+=(need-ans);\n                ans = need;\n            }\n            ans-=consume;\n        }\n        return tot;\n    }\n};\n```
['C++']