This page is still under construction.

Parts of this page are still being built. What you see may change.

Lineland's Airport

Time limit2sMemory limit128 MB

Summary
Find the position of a length-L window along a piecewise-linear terrain profile that minimizes the area above the flat strip that must be excavated.
Level

Medium6 of 10

Topics
Geometry, Binary search, Prefix sum
Solved
No attempts yet

Problem

Lineland is a strange country. As the name suggests, its shape as seen from above is just a straight line rather than a two-dimensional figure. The landscape along this line is very mountainous, which occasionally leads to problems. One such problem occurs now: in this modern era the king wants to build an airport to stimulate the country's economy. Unfortunately, airplanes cannot land on steep airstrips, so a horizontal piece of land is needed. To accommodate the larger airplanes, this strip must have length at least LL.

Over the years, the inhabitants of Lineland have become very proficient at flattening pieces of land. Given a piece of land, they can remove rock quickly. They do not want to add rock, as that may lead to an unstable landing strip, so they can only lower the terrain, never raise it. To minimize their effort, they want to remove the least amount of rock necessary to reach their goal: a flat piece of land of length LL. What is this minimum amount? Because of the low-dimensional nature of Lineland, the amount of rock that must be removed is measured as the total area of land lying above the place where the strip is placed — the shaded region above the airstrip in the cross-section — rather than as a volume.

Input

The first line contains a positive number of scenarios (at most 2525). Then, for each scenario:

  • One line with two integers NN and LL: the number of points, 2≤N≤5002 \le N \le 500, and the required flat length, 1≤L≤100001 \le L \le 10000.
  • NN lines, each with two integers xix_i and yiy_i with 0≤xi,yi≤100000 \le x_i, y_i \le 10000, describing the landscape. The xix_i are in strictly ascending order. At position xix_i the height of the landscape is yiy_i, and between two consecutive xix_i the landscape has constant slope (so the landscape is piecewise linear). It is guaranteed that xN−x1≥Lx_N - x_1 \ge L.

Output

For each scenario, output one line with the minimum amount of rock that must be removed in order to build the airport. This value is uniquely determined. Print it rounded to four decimal places (for example, 0.9000); all test data is chosen so that this rounding is unambiguous.

Examples2

  1. Example 1

    Input
    4
    3 5
    0 2
    4 2
    14 0
    4 3
    0 2
    2 0
    4 0
    5 3
    3 10
    10 2
    30 2
    35 7
    2 777
    222 333
    4444 5555
    
    Expected output
    0.9000
    0.3750
    0.0000
    373362.4867
    
  2. Example 2

    Input
    1
    2 5
    0 3
    10 3
    
    Expected output
    0.0000