Official algorithmic problem description and constraints.
Chef is playing a computer game. There are π monsters on the number line.
Chef is at position 0 on the number line. Initially, the ith monster has health equal to π»πβ and is at the position π΄πβ on the line.
It is guaranteed that π΄π<π΄π+1β for every 1β€π<π.
Every second, the following happens:
If any monster reaches position 0, Chef loses.
If Chef manages to kill all the monsters before any of them reach position 0, he wins.
Before the start of the game, Chef can plant a bomb at any position on the line.
If the bomb is placed at position π, all monsters whose starting positions lie between πβπΎ and π+πΎ will die immediately, and the game will start with the remaining monsters.
If Chef places the bomb optimally, can he win the game?
Detailed video explanations, mathematical intuition, and clean C++ implementation code.