Minimum Amount of Damage Dealt to Bob

You are given an integer power and two integer arrays damage and health, both having length n.

Bob has n enemies, where enemy i will deal Bob damage[i] points of damage per second while they are alive, meaning health[i] > 0.

Every second, after the enemies deal damage to Bob, he chooses one enemy that is still alive and deals power points of damage to them.

Determine the minimum total amount of damage points that will be dealt to Bob before all n enemies are dead.

Example 1
Inputpower = 4, damage = [1,2,3,4], health = [4,5,6,8]
Output39
Attacking enemies in order 3, 2, 0, 1 results in damage 20 + 12 + 3 + 4 = 39, which is minimum.
Example 2
Inputpower = 1, damage = [1,1,1,1], health = [1,2,3,4]
Output20
Attacking enemies in order 0, 1, 2, 3 results in damage 4 + 6 + 6 + 4 = 20, which is minimum.

Constraints

  • 1 <= power <= 10^4
  • 1 <= n == damage.length == health.length <= 10^5
  • 1 <= damage[i], health[i] <= 10^4

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate