2026: [USACO 2024 February Contest Silver] Problem 1. Target Practice II
题目描述
Note: The large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
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 .
输入
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.
输出
样例输入
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
样例输出
17
-1
11
提示
One optimal assignment for test case 1 is the following target vertices 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:
- Input 2: is the same for all .
- Input 3-9: The sum of across all test cases is at most .
- Inputs 10-15: No additional constraints.