Under construction

Still being built. Things may change

Cleanup

Interview

Time limit8sMemory limit1024 MB

Summary
Group the sorted debris sites into piles, paying T per pile plus the bulldozing cost to each pile's weighted median, and find the minimum total time.
Level

Medium6 of 10

Topics
Dynamic programming, Prefix sum, Sorting
Solved
No attempts yet

Problem

It often takes months or even years to clean up after a major hurricane. Mud and debris pile up, and contaminants (see the previous problem) can make the work harder. This problem asks you to plan how a cleanup crew clears debris along one road.

Cleanup uses a bulldozer to push debris into a few large piles, and then trucks load the piles. Each pile a truck picks up takes a fixed time T, no matter how much debris it holds. The driver must complete a lot of paperwork for each pile, while driving there and loading take negligible time.

The piles are formed by bulldozing debris. You are given how much debris starts at each location, and you decide where to move it. You may move nothing at all, but then each original pile must be picked up separately, which may not be optimal. Moving u units of debris a distance d with the bulldozer takes u×du \times d time. Given the debris at each location, compute the minimum total time to form the piles with the bulldozer and then pick them up with trucks. The trucks start only after the bulldozer has finished.

Input

The first line contains the number of data sets 1≤K≤1001 \le K \le 100. Then K data sets follow.

The first line of each data set contains two integers n and T, where 1≤n≤2001 \le n \le 200 is the number of original debris locations and 0≤T≤10000000 \le T \le 1000000 is the time for one truck trip.

The next line contains 2n integers ℓi\ell_i and did_i. Here 0≤ℓi≤10000000 \le \ell_i \le 1000000 is the location along the road of the i-th debris collection point, and 1≤di≤10000001 \le d_i \le 1000000 is the amount of debris there. The pairs are sorted by strictly increasing ℓi\ell_i.

Output

For each data set, print a line Data Set x: where x is the data set number. On the next line, print the minimum total time for the cleanup (bulldozer time plus truck time). Print a blank line after each data set.

Examples1

  1. Example 1

    Input
    1
    8 20
    0 4 3 4 5 2 11 1 18 1 39 1 41 2 42 5
    
    Expected output
    Data Set 1:
    84