#P1020. Problem 1. Target Practice II
Problem 1. Target Practice II
当前没有测试数据。
一、Problem Name
Target Practice II
二、Problem Description
The Paris Moolympics are coming up and Farmer John is training his team of 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 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 (), and each target is a rectangle where target has its lower left coordinate at and its upper right coordinate at . The coordinates also satisfy and (Note: is the same for every target).
In addition, each cow has a "focus" angle they are working on. Therefore, they will turn at a specific angle when shooting. Given that their shot travels in a straight line from their position towards their assigned vertex, the trajectory of cow 's arrow can be described by (), the slope of the trajectory.
So that he can carefully examine the cows' technique, Farmer John wants to minimize the distance between the furthest cows. If Farmer John were to optimally assign each cow to a target vertex and place them on the -axis, can you help him determine what the minimum distance between the furthest cows would be or if the cows will always fail the exercise?
Each input contains () independent test cases. The sum of across all test cases is guaranteed to not exceed .
三、Input Format (input arrives from the terminal / stdin)
- The first line contains (), the number of independent 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 left - most -coordinate of the targets respectively.
- This is followed by lines with the -th line consisting of three integers, , , and , the lower -coordinate, the upper -coordinate, and the right -coordinate of the -th target respectively.
- The last line consists of integers, where denotes the slope of cow 's shot trajectory.
四、Output Format (print output to the terminal / stdout)
The minimum possible distance between the furthest cows or if the cows will always fail the exercise.
五、Sample Input and Output
Sample Input
3
2 1
1 3 6
4 6 3
1 -1 2 -2 3 -3 4 -4
2 1
1 3 6
4 6 3
1 1 2 2 3 3 4 4
2 1
1 3 3
4 6 3
1 -1 2 -2 3 -3 4 -4
Sample Output
17
-1
11
Explanation: For test case 1, one optimal assignment is the following target vertices for cows 1 - 8 respectively: , , , , , , , . This gives the following locations for cows 1 - 8 respectively: , , , , , , , . This gives a minimum distance of . One reason the second test case is impossible is because it is impossible to shoot the vertex at (the top right vertex of target 1) without the shot passing through the interior of target 1.
六、Scoring Rules
- Input 2: is the same for all .
- Inputs 3 - 9: The sum of across all testcases is at most .
- Inputs 10 - 15: No additional constraints.
Problem credits: Suhas Nagar.