Last Hit
Time limit10sMemory limit512 MB
Choose which monsters to last-hit for gold while a tower shoots the closest living monster on its own turns.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
Diana wants to earn as much gold as she can in her favorite game. She is standing next to her own tower, facing monsters. Diana and the tower take turns attacking the monsters, and Diana attacks first. On her turn Diana may pick one living monster and shoot it, and she may also do nothing and pass the turn. On its turn the tower shoots the living monster closest to it. Neither Diana nor the tower attacks a dead monster.
A shot from Diana lowers the monster's hit points by , and a shot from the tower lowers them by . A monster whose hit points drop below dies. Monster starts with hit points. If Diana's shot kills monster , she receives gold. If the tower's shot kills it, she receives nothing. Find the largest amount of gold Diana can obtain.
Input
The first line contains the number of test cases . The first line of each test case contains , and , separated by spaces. The -th of the next lines contains and , separated by a space.
The monsters are listed in order of their distance from the tower. The tower shoots monster only after every monster with a smaller number is dead.
Limits
Output
For each test case, print one line in the format Case #x: y, where is the test case number starting from and is the largest amount of gold Diana can obtain.
Hint
In the sample test case with and , Diana should give up the first monster. If she spends her first two turns on the third monster and brings it down to hit points, she takes the last hit on both the second and the third monster.