Maximum Overkill
Description:
You are a powerful wizard with many enemies. Thinking themselves very clever, they have teamed up to storm your tower and put an end to your arcane research. They underestimate you! You have long prepared for this day, readying spells of elemental annihilation to stop them dead in their tracks. But merely "dead" is too good for these fools. You will use your spells to kill them so dead that none will dare oppose you ever again.
Write a function that returns the maximum possible overkill damage, given:
enemies: an array of integers representing the health of each of your enemies, and
spells: an array of integers representing the damage that each of your spells deal
- Each spell can be used at most once to deal its damage to a single enemy.
- You overkill an enemy when a spell reduces its health below 0: using a 150-damage spell on a 100-health enemy will put its health to -50, which counts as 50 overkill damage.
- You can't cast spells on enemies that are already dead, i.e. enemies with 0 or less health. Blowing up corpses isn't impressing anyone.
- You are looking to maximize the summed overkill damage dealt to all enemies. If your enemies are left at 0, -10, and -99, your total overkill is 109.
- You must kill all enemies if possible. Return -1 if it is not possible.
- It isn't always necessary to use all of your spells.
For example: given [50, 100] for enemies and [50, 100, 100] for spells, you have a few options:
- Deal 50 damage to the 50-health enemy and 100 damage to the 100-health enemy, killing them both exactly. This results in 0 overkill. Remember that the second 100-damage spell is unusable at this point because both enemies are already dead.
- Deal 100 damage to the 50-health enemy and 100 to the 100. This puts one enemy at -50 and one at 0, a total of 50 overkill.
- Deal 100 damage to the 50-health enemy and 50 to the 100, bringing it to 50 health, then finish it with the other 100-damage spell. That brings both enemies to -50 health, a total of 100 overkill.
Thus, overkill([50, 100], [50, 100, 100])
should return 100
. Check the test cases for more examples.
Similar Kata:
Stats:
Created | Sep 16, 2018 |
Published | Sep 16, 2018 |
Warriors Trained | 60 |
Total Skips | 0 |
Total Code Submissions | 35 |
Total Times Completed | 7 |
Python Completions | 7 |
Total Stars | 1 |
% of votes with a positive feedback rating | 25% of 2 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 2 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |