Tap here to switch tabs
Problem
Submissions

Problem: Minimum Initial Energy to Finish Tasks

med
30 min
Try to solve the Minimum Initial Energy to Finish Tasks problem.

Statement

You are given an array tasks where tasks[i] = [actuali_i, minimumi_i]:

  • actuali_i is the actual amount of energy consumed to finish the iextthi^{ ext{th}} task.

  • minimumi_i is the minimum amount of energy required to begin the iextthi^{ ext{th}} task.

For example, if a task is [[ 11, 55 ]], you need at least 55 energy to start it, and after finishing it, your energy decreases by 11.

You can finish the tasks in any order. Return the minimum initial amount of energy needed to finish all the tasks.

Constraints:

  • 1≤1 \leq tasks.length ≤105\leq 10^5

  • 1≤1 \leq actuali≤_i \leq minimumi≤104_i \leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Initial Energy to Finish Tasks

med
30 min
Try to solve the Minimum Initial Energy to Finish Tasks problem.

Statement

You are given an array tasks where tasks[i] = [actuali_i, minimumi_i]:

  • actuali_i is the actual amount of energy consumed to finish the iextthi^{ ext{th}} task.

  • minimumi_i is the minimum amount of energy required to begin the iextthi^{ ext{th}} task.

For example, if a task is [[ 11, 55 ]], you need at least 55 energy to start it, and after finishing it, your energy decreases by 11.

You can finish the tasks in any order. Return the minimum initial amount of energy needed to finish all the tasks.

Constraints:

  • 1≤1 \leq tasks.length ≤105\leq 10^5

  • 1≤1 \leq actuali≤_i \leq minimumi≤104_i \leq 10^4