C++ | greedy solution with Intution for sorting
Intuition1st Intution :After observation, I take the sum of all the the actual time, then one by one check for each task the answer, if we take the task in last
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
### 1st Intution :
After observation, I take the sum of all the the actual time, then one by one check for each task the answer, if we take the task in last. If we take a task_i in last then we will not take the actual_time[i] of that task instead we will take the minimum_time[i], so the answer will be min(sum(actual_time)- actual_time[i] + minimum_time[i]).
But this approach was wrong, as we are not checking the middle state. what will happen for case like below:
[[1,1],[1,3]], it will give answer 2, but the actual answer is 3.
This lead to reach conclusion we need some order i.e. we need to sort in some order.

### 2nd Intution :
Continuing with previous approach, We just need to find out at any middle state ,if we are getting result, We have to find out a order.
After observation, we need to process the task first whose actual_time + the minimum_time of the next task is minimum. i.e. a[0] + b[1] < b[0] + a[1]. or we can a[0] - a[1] < b[0] - b[1].
In this way we will figure out for each task what might be the maximum answer, our result will be maximum of all these time.

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

# Code
```cpp []
class Solution {
public:
    static bool cmp(vector<int> &a, vector<int> &b){
        return a[0] + b[1] < b[0] + a[1];
    }
    int minimumEffort(vector<vector<int>>& tasks) { 
        sort(tasks.begin(), tasks.end(), cmp);
        long long res = -1e10;
        long long ps = 0;
        for(int i = 0; i < tasks.size(); i++){
            res = max(res, ps + tasks[i][1]);
            ps +=tasks[i][0];   
        }
        return res;
    }

};
```
['Greedy', 'Sorting', 'C++']