Cleanup
InterviewTime limit8sMemory limit1024 MB
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 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 . Then K data sets follow.
The first line of each data set contains two integers n and T, where is the number of original debris locations and is the time for one truck trip.
The next line contains 2n integers and . Here is the location along the road of the i-th debris collection point, and is the amount of debris there. The pairs are sorted by strictly increasing .
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.