Minimum Amount of Damage Dealt to Bob - Problem
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 (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 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.
Input & Output
Example 1 — Basic Case
$
Input:
power = 10, damage = [10,4,15], health = [80,20,40]
›
Output:
138
💡 Note:
Enemy ratios: 10/8=1.25, 4/2=2.0, 15/4=3.75. Attack order [2,1,0] gives minimum damage of 138.
Example 2 — Equal Ratios
$
Input:
power = 5, damage = [5,10], health = [10,20]
›
Output:
30
💡 Note:
Both enemies have ratio 5/2=2.5. Either order works, total damage is 30.
Example 3 — Single Enemy
$
Input:
power = 20, damage = [15], health = [30]
›
Output:
30
💡 Note:
Only one enemy: takes 2 turns to kill, deals 15 damage per turn, total 30.
Constraints
- 1 ≤ power ≤ 104
- 1 ≤ n ≤ 105
- 1 ≤ damage[i], health[i] ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Battle Setup
Bob faces multiple enemies, each dealing damage per turn
2
Turn Mechanics
Enemies attack first, then Bob attacks one enemy
3
Optimal Strategy
Attack enemies with highest damage/time ratio first
Key Takeaway
🎯 Key Insight: Prioritize enemies by damage-per-time ratio to minimize total damage taken
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code