Editorial for WC '18 Contest 2 J4 - Ammunition
Submitting an official solution before solving the problem yourself is a bannable offence.
Let's refer to guards whose values are as zero-guards, and to the remaining guards as positive-guards. A few useful observations can be made:
- If Ethan has at least bullets, and he tranquilizes a zero-guard, he'll still have at least bullet afterwards. There's no harm in doing this whenever possible.
- If Ethan has exactly bullet, and he tranquilizes a zero-guard, he'll have bullets afterwards and will need to stop. This should only be done when no other options remain.
- If Ethan has at least bullet, and he tranquilizes a positive-guard, he'll still have at least bullet afterwards. The only harm in doing this is based on how many excess bullets are wasted due to the gun's capacity being reached (which is worse the more bullets Ethan has). Therefore, this should only be done when Ethan has exactly bullet, unless no other options remain.
This suggests an optimal greedy strategy for Ethan to follow at each point in time:
- If Ethan has bullets remaining or there are guards left, stop.
- If all remaining guards are positive-guards, tranquilize all of them in any order.
- If Ethan has bullet remaining and there's at least positive-guard, tranquilize any positive-guard.
- Otherwise, tranquilize any zero-guard.
It's possible to simulate this strategy in time.
It's also possible to consider what exactly will occur over the course of the strategy and come up with a closed-form answer without needing to simulate it. Firstly, if , then the answer is . Otherwise, the answer is at most , and at most the total number of bullets which Ethan loads into his gun (including the initial bullets). For each positive-guard , he can tranquilize them when he has exactly bullet and thus load bullets into his gun (unless he has so many bullets that he's forced to shoot a positive-guard while having or more bullets, in which case the answer will come out to either way). This gives us an answer of:
when , which may be evaluated in time.
Comments