Find the smallest launch power whose chain of shrinking blast radii clears all hay bales on a line.
Medium7Binary searchDynamic programmingTwo pointersNo attempts yetTime limit2sMemory limit512 MBBessie built a game called "Angry Cows". A slingshot launches one cow onto a number line, and the goal is to detonate every hay bale on that line.
There are N hay bales at distinct integer positions x1,x2,…,xN. A cow launched with power R that lands at position x detonates every hay bale in the range x−R to x+R. Those bales then all explode at the same time with blast radius R−1, and every bale caught in one of those blasts that has not exploded yet explodes at the same time with blast radius R−2. The chain continues until no new bale explodes or the radius drops below 0.
The landing position does not have to be an integer. Find the smallest power R for which some landing position detonates all N bales.
The first line contains N (2≤N≤50000).
Each of the next N lines contains one position xi (0≤xi≤1000000000). All positions are distinct, and they are not necessarily sorted.
Print the smallest power R that detonates every hay bale, with exactly one digit after the decimal point. The answer is always a multiple of 0.5.
Suppose the bales sit at 1,3,8,10,11. A cow launched with power 3 that lands at position 5 detonates the bales at 3 and 8. Those two explode together with radius 2 and catch the bales at 1 and 10, which explode together with radius 1 and catch the bale at 11. The last bale explodes with radius 0.