This page is still under construction.

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

Off the Rails

Time limit5sMemory limit512 MB

Summary
Given n cities sorted by x, cover them with straight non-vertical segments so that the sum of squared vertical distances plus C per segment is minimized.
Level

Hard8 of 10

Topics
Dynamic programming, Geometry, Math, Greedy
Solved
No attempts yet

Problem

The Country of Everlasting is planning a rail line that connects its cities. The route has to keep the distance between the cities and the rail line as small as possible. While canvassing materials, the engineers found that buying pre-fabricated guideways from the country of Forever is the best option. Forever sells straight guideways only. If the chosen route is not a single straight line (as in the figure below), several pre-fabricated guideways are needed. Guideways of different lengths may be bought.

A route built from several straight guideways

Every pre-fabricated guideway imported from Forever carries an overhead cost of CC. The route therefore has to minimize a+bCa + bC, where:

  • aa is the sum of the squares of the lengths of the vertical segments from each city to the rail line.
  • bb is the number of pre-fabricated guideways.

These rules also hold:

  • The guideways need not be connected to one another.
  • No guideway may be placed vertically.
  • No vertical line meets the interiors of two guideways at two different points.

Input

The first line contains TT, the number of test cases.

The first line of each test case contains an integer nn and a real number CC, separated by one space. Each of the next nn lines describes one city. The iith of those lines contains two integers xix_i and yiy_i, the coordinates of the iith city.

Constraints

  • 1≤T≤2001 \le T \le 200
  • 1≤n≤10001 \le n \le 1000
  • −1000≤xi,yi≤1000-1000 \le x_i, y_i \le 1000
  • 0<C≤10000.0000 < C \le 10000.000
  • CC is given with at most 3 decimal places.
  • x1<x2<x3<⋯<xnx_1 < x_2 < x_3 < \cdots < x_n

Output

For each test case, print the minimum value of a+bCa + bC on its own line. Round at the fifth decimal place and print exactly four digits after the decimal point, keeping trailing zeros. A value of 11 is printed as 1.0000.

Examples2

  1. Example 1

    Input
    2
    10 1.0
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10 10
    8 2.0
    1 1
    2 2
    3 1
    4 2
    5 1000
    6 999
    7 1000
    8 999
    
    Expected output
    1.0000
    5.6000
    
  2. Example 2

    Input
    2
    5 0.5
    0 0
    1 0
    2 0
    3 100
    4 100
    5 400.0
    0 0
    1 0
    2 0
    3 100
    4 100
    
    Expected output
    1.0000
    800.0000