Minimum Initial Energy to Finish Tasks

Hard · Greedy · about 25 minutes

Asked at Amazon, Google, Microsoft.

tasks[i] = [actual, minimum]: task i costs actual energy, and you need at least minimum energy to start it. Do the tasks in any order. Return the minimum initial energy needed to finish them all.