Sorting | Easy Solution | 29ms | Beats 93%
Complexity
Time complexity: O(n)

Space complexity: O(1)
Code
# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)

# Code
```cpp []
class Solution {
public:
    int minimumEffort(vector<vector<int>>& tasks) {
        sort(tasks.begin(),tasks.end(),[](vector<int> &a, vector<int> &b){
            return a[1]-a[0] > b[1]-b[0];
        });

        int currEnergy = 0,ans = 0;
        for(auto &task : tasks){
            int req = task[0],minReq = task[1];
            if(currEnergy < minReq){
                ans += minReq - currEnergy;
                currEnergy = minReq;
            }
            currEnergy -= req;
        }

        return ans;
    }
};
```
['Sorting', 'C++']