Python 3 | Sort + Greedy & Sort + Binary Search | Explanation
Approach \#1 - Binary Search\n- Sort by difference\n- Use binary search validate if given input (energy) can finish all works\n- Search the smallest possible (l
### Approach \\#1 - Binary Search\n- Sort by difference\n- Use binary search validate if given input (energy) can finish all works\n- Search the smallest possible (like `bisect_left`)\n```\nclass Solution:\n    def minimumEffort(self, tasks: List[List[int]]) -> int:\n        tasks.sort(key=lambda x: x[0]-x[1])\n        def ok(mid):\n            for actual, minimum in tasks:\n                if minimum > mid or actual > mid: return False\n                if minimum <= mid: mid -= actual\n            return True\n        l, r = 0, 10 ** 9\n        while l <= r:\n            mid = (l+r) // 2\n            if ok(mid): r = mid - 1\n            else: l = mid + 1\n        return l\n```\n\n### Approach \\#2 - Greedy\n- Sort by difference\n- `cur`: actual cost, `ans` adjust by `minimum` so that it can start for all works\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, minimum in tasks:\n            ans = min(cur-minimum, ans)\n            cur -= cost\n        return -ans\n```
['Binary Search', 'Greedy', 'Python', 'Python3']