Angry Cows (Bronze)
InterviewTime limit2sMemory limit512 MB
Starting from the best bale, count how many bales explode as the blast radius grows by one each step.
- Level
Easy3 of 10
- Topics
- Simulation, Sorting
- Solved
- No attempts yet
Problem
Bessie 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 hay bales at distinct integer positions on a number line. If the cow lands on the bale at position , that bale explodes with a blast radius of , so every other bale at distance at most is engulfed. The engulfed bales all explode together at the next time step, each with a blast radius of , so any bale that has not exploded yet and sits at distance at most is engulfed as well. At the following time step those newly engulfed bales explode with radius . In general, a bale that explodes at time has blast radius , and every bale engulfed by such an explosion explodes at time with radius . 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.
Input
The first line contains the number of hay bales ().
Each of the next lines contains one position ().
All positions are distinct, and they are not necessarily given in increasing order.
Output
Print the largest number of hay bales that a single cow can detonate.
Hint
In the first example, launching the cow onto the bale at position engulfs the bales at positions and , and both explode with radius . Those two explosions engulf the bales at positions and , which explode with radius . Radius is not enough to reach the bale at position .