Starting from the best bale, count how many bales explode as the blast radius grows by one each step.
Easy3SimulationSortingInterviewNo attempts yetTime limit2sMemory limit512 MBBessie the cow has designed a video game she calls "Angry Cows". The player uses a slingshot to launch a single cow onto one of the hay bales that sit on a number line. The bale the cow lands on explodes, and the blast spreads to nearby bales and starts a chain reaction. The goal is to detonate as many bales as possible with one cow.
There are N hay bales at distinct integer positions x1,x2,…,xN on a number line. If the cow lands on the bale at position x, that bale explodes with a blast radius of 1, so every other bale at distance at most 1 is engulfed. The engulfed bales all explode together at the next time step, each with a blast radius of 2, so any bale that has not exploded yet and sits at distance at most 2 is engulfed as well. At the following time step those newly engulfed bales explode with radius 3. In general, a bale that explodes at time t has blast radius t, and every bale engulfed by such an explosion explodes at time t+1 with radius t+1. A bale that has already exploded never explodes again.
Find the largest number of hay bales that explode when the cow is launched onto the best possible bale.
The first line contains the number of hay bales N (1≤N≤100).
Each of the next N lines contains one position xi (0≤xi≤109).
All positions are distinct, and they are not necessarily given in increasing order.
Print the largest number of hay bales that a single cow can detonate.
In the first example, launching the cow onto the bale at position 5 engulfs the bales at positions 4 and 6, and both explode with radius 2. Those two explosions engulf the bales at positions 3 and 8, which explode with radius 3. Radius 3 is not enough to reach the bale at position 13.