Proud Penguin
Time limit3sMemory limit256 MB
Distribute at most W units of water into level pools along a polygonal track to minimize the tallest uphill stretch penguins must climb.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Geometry
- Solved
- No attempts yet
Problem
Proud Penguin (PP) is one of the busiest attractions in the city. It specializes in the arctic, so visitors see fish, seals, whales and penguins. The penguins drew such crowds that PP decided to build a new area for them to play in.
The new area is a long, narrow track of climbs and slides. The ends are the highest points, so a trip always starts with a slide. Penguins enter at one end and reach the other by waddling, swimming and sliding.
One question is left in the planning stage. How should PP spread the water along the track? Penguins are lazy, so PP wants the highest climb to be as low as possible. The board also capped the amount of water, to keep maintenance cheap.
You are given the height of the track at evenly spaced points and the amount of water available. Find the lowest possible height of the highest climb the penguins are left with.

Figure 1: measuring the height of climbs
The track and the water
The cross section of the track is the polyline through the points . The track is one unit wide and runs in a straight line between two neighbouring points.
Water runs downhill, so the surface of one pool is level and every piece of ground below that level is under water. The two ends have height 100 and no other point is higher, so no water leaves the track. Water is measured by cross-section area, and the areas of all pools add up to at most .
Climbs
After the water is poured, the surface is the ground where it is dry and the water level where it is flooded. A climb is a maximal stretch of that surface along which the height keeps rising, and the height of the climb is the height at its top minus the height at its bottom. A flat stretch ends a climb. A climb can therefore start at a water line, and level ground between two points of equal height ends a climb as well. Penguins travel in both directions, so climbs that rise to the left and climbs that rise to the right both count.
Make the highest climb as low as you can and print its height.
Input
The first line contains the number of test cases . The first line of each test case contains the length of the track and the amount of water available . The next line contains integers , where is the height at the left end, is the height one unit from the left end, and is the height at the right end.
Output
For each test case, print on one line the lowest possible height of the highest climb, rounded to four digits after the decimal point. In every test case the answer is farther than from a rounding boundary, so computing it to an accuracy of is enough.