Python, sort then dp
Sort by minimum_i - actual_i, then do dp.\n\nYou can show that if you have minimum_i - actual_i not in sorted order, you can swap them and using bubble sort eve
Sort by `minimum_i - actual_i`, then do dp.\n\nYou can show that if you have `minimum_i - actual_i` not in sorted order, you can swap them and using bubble sort eventually sort them and still have valid solution (with same initial amount of energy). Just write down inequalities.\n\nNow after sorting we get easy dp, where at step `i` we need to have `max(minimum_i, actual_i + dp[i + 1])` energy to finish remaining tasks.\n\n\n```\nclass Solution:\n    def minimumEffort(self, tasks) -> int:\n        n = len(tasks)\n        tasks.sort(key=lambda p: -p[1] + p[0])\n        dp = [0] * n\n        dp[-1] = max(tasks[-1][1], tasks[-1][0])\n        for i in range(n - 2, -1, -1):\n            dp[i] = max(tasks[i][1], tasks[i][0] + dp[i + 1])\n        return dp[0]\n```
[]