simple intuitive sort and count, a minumum effort solution heheh
Intuition\nUse some math intuition (or try several stategies to pass the test cases) to realize that the optimal order to complete tasks is starting with the ta
# Intuition\nUse some math intuition (or try several stategies to pass the test cases) to realize that the optimal order to complete tasks is starting with the tasks that have the highest difference of `minimum[i] - actual[i]`. Then just straigh up calculate how much energy you need to complete them in that order.\n\n# Approach\nSort the tasks. Initialize current energy and the minimum starting amount to the `minimum[0]` or 0. Iterate through tasks. If at any point you don\'t have enough energy to start, add the needed amount to your current energy and the minimum starting amount. If after completing a task you have negative energy, restore it and also add the restore cost to the minimum starting amount.\n\n# Complexity\n- Time complexity:\n$$O(n* log(n))$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\n/**\n * @param {number[][]} tasks\n * @return {number}\n */\nvar minimumEffort = function(tasks) {\n    tasks.sort((a, b) => (b[1] - b[0]) - (a[1] - a[0]));\n    console.log(tasks);\n    let ans = tasks[0][1];\n    let cur = ans;\n    for (let task of tasks) {\n        const add1 = Math.max(0, task[1] - cur);\n        cur += add1;\n        ans += add1;\n\n        cur -= task[0];\n        const add2 = Math.max(0, -cur);\n        cur += add2;\n        ans += add2;\n    }\n    return ans;\n};\n```
['JavaScript']