Watering the Bean Plants
Time limit10sMemory limit256 MB
Place at most one disk of radius R and cover the uncovered parts of N segments with unit-length sticks at minimum total cost.
- Level
Hard9 of 10
- Topics
- Geometry, Greedy, Brute force
- Solved
- No attempts yet
Problem
Kyeonggeun gave his bean plants plenty of fertilizer and no water, so the plants rotted. This time he wants equipment that waters all of them.
The bean plants grow along line segments in the plane and fill each segment completely. Each segment joins two different points.
Kyeonggeun picks at most one point of the plane and installs a sprinkler there. The sprinkler waters every plant whose distance from that point is at most , and it costs . He may also install no sprinkler.
Every plant left outside the sprinkler range needs a waterer. One waterer is a straight piece of length exactly and waters only the plants it lies on. It cannot be cut, and one piece costs . He places as many pieces as he wants, anywhere and in any direction, and the pieces may overlap or stick out past the end of a segment.
Compute the smallest cost of watering every plant.
Input
The first line has the number of test cases .
The first line of each test case has the number of segments (), the radius of the sprinkler range (), the price of the sprinkler (), and the price of one waterer ().
Each of the next lines has the start point , and the end point , of one segment, separated by spaces (). The start point and the end point are different.
No two segments touch or overlap, and the lengths of the segments add up to at most .
Every input value is an integer.
Output
For each test case, print on its own line the smallest cost of watering every plant.