#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 NN (1N41041\leq N\leq4\cdot10^4) axis - aligned rectangular targets and 4N4N cows. Every cow must be assigned to a different target vertex. At moment ii, for 1iN1\leq i\leq N:

  1. Target ii appears.
  2. The 44 cows assigned to its vertices shoot at them.
  3. 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.
  4. The target disappears to make space for the next one.

Each cow is located on the yy-axis (x=0x = 0), and each target is a rectangle where target ii has its lower left coordinate at (X1,y1(i))(X_1,y_1^{(i)}) and its upper right coordinate at (x2(i),y2(i))(x_2^{(i)},y_2^{(i)}). The coordinates also satisfy 1X1<x2(i)1091\leq X_1<x_2^{(i)}\leq10^9 and 1y1(i)<y2(i)1091\leq y_1^{(i)}<y_2^{(i)}\leq10^9 (Note: X1X_1 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 ii's arrow can be described by sis_i (0<si<1090<\vert s_i\vert<10^9), 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 yy-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 TT (1T101\leq T\leq10) independent test cases. The sum of NN across all test cases is guaranteed to not exceed 41044\cdot10^4.

三、Input Format (input arrives from the terminal / stdin)

  1. The first line contains TT (1T101\leq T\leq10), the number of independent test cases. Each test case is described as follows:
    • The first line of each test case contains two integers, NN and X1X_1, the number of targets and the left - most xx-coordinate of the targets respectively.
    • This is followed by NN lines with the ii-th line consisting of three integers, y1(i)y_1^{(i)}, y2(i)y_2^{(i)}, and x2(i)x_2^{(i)}, the lower yy-coordinate, the upper yy-coordinate, and the right xx-coordinate of the ii-th target respectively.
    • The last line consists of 4N4N integers, s1,s2,,s4Ns_1,s_2,\cdots,s_{4N} where sis_i denotes the slope of cow ii's shot trajectory.

四、Output Format (print output to the terminal / stdout)

The minimum possible distance between the furthest cows or 1-1 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: (6,1)(6,1), (6,3)(6,3), (3,4)(3,4), (3,6)(3,6), (1,4)(1,4), (1,3)(1,3), (1,6)(1,6), (1,1)(1,1). This gives the following yy locations for cows 1 - 8 respectively: 5-5, 99, 2-2, 1212, 11, 66, 22, 55. This gives a minimum distance of 12(5)=1712 - (-5) = 17. One reason the second test case is impossible is because it is impossible to shoot the vertex at (6,3)(6,3) (the top right vertex of target 1) without the shot passing through the interior of target 1.

六、Scoring Rules

  1. Input 2: si\vert s_i\vert is the same for all 1i4N1\leq i\leq4N.
  2. Inputs 3 - 9: The sum of NN across all testcases is at most 10001000.
  3. Inputs 10 - 15: No additional constraints.

Problem credits: Suhas Nagar.