[Python] clean greedy solution with explanation
Idea\n\nFor task = [cost, mmin], it needs mmin energy to start but only needs cost energy to finish. Let\'s define mmin - cost as the energy saved for this task
**Idea**\n\nFor `task = [cost, mmin]`, it needs `mmin` energy to start but only needs `cost` energy to finish. Let\'s define `mmin - cost` as the energy `saved` for this task.\n\nTo start a new task, we need to add `mmin - prev_saved` energy. Therefore, we want to complete the tasks with higher `saved` first so as to maximize `prev_saved`. This leads to a greedy solution.\n\nThe order doesn\'t matter for tasks with the same `saved`. These tasks just need `saved + sum(cost)` energy altogether.\n\n\n</br>\n\n**Complexity**\n\n- Time complexity: `O(NlogN)`\n- Space complexity: `O(1)`\n\n</br>\n\n**Python**\n\n```\nclass Solution:\n    def minimumEffort(self, tasks: List[List[int]]) -> int:\n        tasks.sort(key=lambda x: x[0] - x[1])\n        ans = cur = 0\n        for cost, mmin in tasks:\n            if mmin > cur:\n                ans += (mmin - cur)\n                cur = mmin\n            cur -= cost\n        return ans\n```\n
[]