Sort + memoization C++ using greedy approach
Intuition\n- We need to prioritise doing tasks first which has higher difference actual and minimum energy. \n- Because they have high barrier (minimum energy) 
# Intuition\n- We need to prioritise doing tasks first which has higher difference actual and minimum energy. \n- Because they have high barrier (minimum energy) but low actual energy as compared to min energy so we need to prioritise them. \n- One way is to sort them by their difference.\n\n# Complexity\n- Time complexity:  O(nlogn)\n- Space complexity: O(n)\n\n# Approach 1\nMemoization\n\n# Code\n```\nclass Solution {\npublic:\n    static const bool cmp(vector<int>& a, vector<int>& b){\n        return a[1] - a[0] > b[1] - b[0];\n    }\n    int dp[100001];\n    int solve(vector<vector<int>>& tasks, int i){\n        if(i == tasks.size())   return 0;\n        if(dp[i] != -1) return dp[i];\n\n        int ans = tasks[i][1];\n        int take = tasks[i][0] + solve(tasks, i+1);\n\n        return dp[i] = max(take, ans);\n    }\n    int minimumEffort(vector<vector<int>>& tasks) {\n        sort(tasks.begin(), tasks.end(), cmp);\n        memset(dp, -1, sizeof dp);\n        return solve(tasks, 0);\n    }\n};\n```\n\n# Approach 2\nTabutation\n\n# Code\n```\nclass Solution {\npublic:\n    static const 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 n = tasks.size();\n        \n        int dp[n+1];\n        memset(dp, 0, sizeof dp);\n        for(int i=tasks.size()-1; i>=0; i--) {\n            dp[i] = max(tasks[i][0] + dp[i+1], tasks[i][1]);\n        }\n        return dp[0];\n    }\n};\n```
['Dynamic Programming', 'Greedy', 'Memoization', 'C++']