Find the fewest days for two eagles dealing LH damage per attack to kill a lion and a bear that heal each night, or output -1.
Medium6Binary searchMathGreedyNo attempts yetTime limit1sMemory limit32 MBTwo twin eagles want to bring down the lion and the bear that live nearby. They are too weak for a head-on fight, so they attack only by surprise.
One eagle attacks for LH damage. The lion has S health and the bear has D health. When one eagle attacks an animal, that animal loses LH health. When both eagles attack the same animal, it loses 2×LH health.
The eagles attack once during each day, starting on day 1. Both of them may hit the same animal, or each of them may hit a different animal. They are weak, so after that one attack they cannot attack again on the same day.
Every night, the lion and the bear recover L and B health, but only if they are still standing. Health can grow without any bound. An animal falls as soon as its health drops to 0 or below, and a fallen animal never recovers and never needs to be attacked again.
Find the smallest number of days the eagles need to bring down both animals.
The first line contains the eagle attack power LH, the lion health S, the bear health D, the lion recovery L, and the bear recovery B, separated by spaces.
Print the smallest number of days needed to bring down both the lion and the bear. The answer can exceed the range of a 32-bit integer.
If the eagles can never bring down both animals, no matter how many days pass, print -1.