C++ || very simple sorting solution || 🚀🚀 beats 90% 🚀🚀
\n# Code\n\nclass Solution {\npublic:\n    bool static cmp(const vector<int>& v1, const vector<int>& v2) {\n        int abs1 = abs(v1[1] - v1[0]), abs2 = abs(v2
\n# Code\n```\nclass Solution {\npublic:\n    bool static cmp(const vector<int>& v1, const vector<int>& v2) {\n        int abs1 = abs(v1[1] - v1[0]), abs2 = abs(v2[1] - v2[0]);\n        return (abs1 == abs2)? v1[1] > v2[1] : abs1 > abs2; \n    }\n    int minimumEffort(vector<vector<int>>& tasks) {\n        ios_base::sync_with_stdio(false);\n\t\tcin.tie(NULL);\n\t\tcout.tie(NULL);\n\n        //we sort based on the difference between initial required energy and energy needed to finish the task\n        sort(tasks.begin(), tasks.end(), cmp);\n        //total amount of enery spent and the current amount of energy we have\n        int ans = 0, current = 0;\n\n        for (auto task : tasks) {\n            //if we dont have enough energy\n            if (current < task[1]) {\n                //add the energy required the start the task\n                int diff = task[1] - current;\n                ans += diff, current += diff;\n            }\n            //spend the amount of energy to finish the task\n            current -= task[0];\n        }\n\n        return ans;\n    }\n};\n```
['Greedy', 'Sorting', 'C++']