Class Solution
-
- All Implemented Interfaces:
public final class Solution3273 - Minimum Amount of Damage Dealt to Bob.
Hard
You are given an integer
powerand two integer arraysdamageandhealth, both having lengthn.Bob has
nenemies, where enemyiwill deal Bobdamage[i]points of damage per second while they are alive (i.e.health[i] > 0).Every second, after the enemies deal damage to Bob, he chooses one of the enemies that is still alive and deals
powerpoints of damage to them.Determine the minimum total amount of damage points that will be dealt to Bob before all
nenemies are dead.Example 1:
Input: power = 4, damage = 1,2,3,4, health = 4,5,6,8
Output: 39
Explanation:
Attack enemy 3 in the first two seconds, after which enemy 3 will go down, the number of damage points dealt to Bob is
10 + 10 = 20points.Attack enemy 2 in the next two seconds, after which enemy 2 will go down, the number of damage points dealt to Bob is
6 + 6 = 12points.Attack enemy 0 in the next second, after which enemy 0 will go down, the number of damage points dealt to Bob is
3points.Attack enemy 1 in the next two seconds, after which enemy 1 will go down, the number of damage points dealt to Bob is
2 + 2 = 4points.
Example 2:
Input: power = 1, damage = 1,1,1,1, health = 1,2,3,4
Output: 20
Explanation:
Attack enemy 0 in the first second, after which enemy 0 will go down, the number of damage points dealt to Bob is
4points.Attack enemy 1 in the next two seconds, after which enemy 1 will go down, the number of damage points dealt to Bob is
3 + 3 = 6points.Attack enemy 2 in the next three seconds, after which enemy 2 will go down, the number of damage points dealt to Bob is
2 + 2 + 2 = 6points.Attack enemy 3 in the next four seconds, after which enemy 3 will go down, the number of damage points dealt to Bob is
1 + 1 + 1 + 1 = 4points.
Example 3:
Input: power = 8, damage = 40, health = 59
Output: 320
Constraints:
<code>1 <= power <= 10<sup>4</sup></code>
<code>1 <= n == damage.length == health.length <= 10<sup>5</sup></code>
<code>1 <= damagei, healthi<= 10<sup>4</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-