Target Practice II
Time limit2.5sMemory limit1024 MB
Assign each of the 4N cows on the y-axis to a distinct target vertex so no shot crosses a target interior, minimizing the largest distance between cows.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Greedy, Sorting
- Solved
- No attempts yet
Problem
Note: The large size of integers involved in this problem may require 64-bit integer data types (e.g., "long long" in C/C++).
The Paris Moolympics are coming up, and Farmer John is training his cows in archery. He has set up the following exercise on the 2D coordinate plane.
There are () axis-aligned rectangular targets and cows. Every cow must be assigned to a different target vertex. At moment , for :
- Target appears.
- The 4 cows assigned to its vertices shoot at them.
- If a cow's shot passes through the interior of the target before it hits the assigned vertex or misses, the cows fail the exercise.
- The target disappears to make space for the next one.
Each cow is located on the -axis (). Target is a rectangle with lower left corner and upper right corner . The coordinates satisfy and . Note that is the same for every target.
Each cow also has a "focus" angle, so it turns to a specific angle when it shoots. A shot travels in a straight line from the cow's position to its assigned vertex. The trajectory of cow has slope ().
Farmer John wants to examine the cows' technique closely, so he wants to minimize the distance between the two cows that are furthest apart. If he assigns each cow to a target vertex optimally and places the cows on the -axis, what is the minimum possible distance between the furthest cows? If the cows will always fail the exercise, output -1 instead.
Input
The first line contains (), the number of test cases. Each test case is described as follows.
The first line of each test case contains two integers and , the number of targets and the leftmost -coordinate of the targets. Then lines follow. The -th line contains three integers , , and , the lower -coordinate, the upper -coordinate, and the right -coordinate of target .
The last line contains integers , where is the slope of cow 's shot. The sum of across all test cases does not exceed .
Output
Print the minimum possible distance between the furthest cows, or if the cows will always fail the exercise.