Zero health with minimum mana
Time limit1sMemory limit128 MB
Each use of a skill costs more than its previous use by K; find the minimum total mana to remove exactly M health.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Math, Greedy
- Solved
- No attempts yet
Problem
Gwanghyeon plays a game called League of Storms. You win by using skills to drop the opponent's health to 0 or below, but Gwanghyeon set his own restriction: bring the health to exactly 0 while spending as little mana as possible.
There are skills. Using skill once spends mana and removes health from the opponent. A skill can be used any number of times, but every repeat of the same skill costs more mana than the previous use of that skill. For example, a skill with a cost of 10 and spends 10 on the first use, 15 on the second, and 20 on the third. The increase is counted separately for each skill, and the order of the uses does not change the total.
The opponent's health is . Find the smallest amount of mana needed to bring it to exactly 0.
Input
The first line contains the number of skills , the enemy's health , and the extra mana added on each repeat of the same skill. ()
Each of the next lines describes one skill with the mana it needs, , and the health it removes, . ()
Every input has at least one combination that brings the enemy's health to exactly 0.
Output
Print on the first line the smallest amount of mana needed to bring the enemy's health to exactly 0.