#P3944. Minimize Shrinking Potions for Lethal Damage
Minimize Shrinking Potions for Lethal Damage
Minimize Shrinking Potions for Lethal Damage
You are given an enemy board with n minions, and the enemy hero has m health points. Each enemy minion has an attack value ki.
You have three types of cards:
- Crazy Potion (cost 1): Pulls an enemy minion onto your board if its current attack ≤ 2.
- Shadow Madness (cost 4): Pulls an enemy minion onto your board if its current attack ≤ 3.
- Shrinking Potion (cost 1): Decreases the attack of all enemy minions by 3 points. (Note: after reduction, assume a minion’s attack cannot contribute if it drops to 0 or below.)
You have an unlimited supply of Crazy Potion and Shadow Madness cards, but you want to use the minimum number of Shrinking Potions possible. When you pull a minion, it attacks the enemy hero exactly once with its current attack (after any Shrinking Potion reductions).
Your goal is to choose a number of Shrinking Potions to use (say, x) and then pull every enemy minion that meets the conditions so that the total damage dealt is at least m, thereby reducing the enemy hero's health to 0 or less.
For each enemy minion with original attack k, after using x Shrinking Potions its attack becomes k - 3x. However, you can only pull that minion if its current attack is less than or equal to 3 and positive. That is, a minion contributes damage only if:
[ \text{if } k - 3x > 0 \text{ and } k - 3x \le 3, \text{ then its damage is } k - 3x; \text{ otherwise, it cannot be pulled.} ]
Determine the minimum nonnegative integer x (the number of Shrinking Potions) required so that the sum of the damage of all eligible pulled minions is at least m. If it is impossible to achieve this goal, output -1.
inputFormat
The first line contains two integers n and m (1 ≤ n ≤ 105, 1 ≤ m ≤ 109), representing the number of enemy minions and the enemy hero's health, respectively.
The second line contains n integers k1, k2, ..., kn (1 ≤ ki ≤ 109), where ki is the attack value of the i-th enemy minion.
outputFormat
Output a single integer: the minimum number of Shrinking Potions required so that, after using them, you can pull enemy minions (using Crazy Potion or Shadow Madness) to deal a total damage of at least m. If it is impossible, output -1.
sample
2 2
2 5
0