Target Practice II

시간 제한2.5초메모리 제한1024 MB

요약
4N마리의 소를 y축에 배치하고 각 소를 서로 다른 목표 꼭짓점에 짝지어 화살이 직사각형 내부를 지나지 않게 하면서 가장 먼 소 사이 거리를 최소화한다.
난이도

어려움10점 중 8점

유형
정렬, 그리디, 이분 탐색, 기하
정답자
아직 제출이 없습니다

문제

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 N(1≤N≤4⋅104)N (1 \leq N \leq 4 \cdot 10^4) axis-aligned rectangular targets and 4N4N cows. Every cow must be assigned to a different target vertex. At moment ii, for 1≤i≤N1 \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=0)(x = 0), and each target is a rectangle where target ii has its lower left coordinate at (X_1,y_1(i))(X\_1, y\_1^{(i)}) and its upper right coordinate at (x_2(i),y_2(i))(x\_2^{(i)}, y\_2^{(i)}). The coordinates also satisfy 1≤X_1<x_2(i)≤1091 \leq X\_1 < x\_2^{(i)}\leq 10^9 and 1≤y_1(i)<y_2(i)≤1091 \leq y\_1^{(i)} < y\_2^{(i)} \leq 10^9 (Note: X_1X\_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 s_is\_i (0<∣s_i∣<109)(0 < |s\_i| < 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 (1≤T≤101 \leq T \leq 10) independent test cases. The sum of NN across all test cases is guaranteed to not exceed 4⋅1044\cdot 10^4.

입력

The first line contains TT (1≤T≤101 \leq T \leq 10), 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 X_1X\_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, y_1(i)y\_1^{(i)}, y_2(i)y\_2^{(i)}, and x_2(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, s_1,s_2,…,s_4Ns\_1, s\_2, \dots, s\_{4N} where s_is\_i denotes the slope of cow ii's shot trajectory.

출력

The minimum possible distance between the furthest cows or −1-1 if the cows will always fail the exercise.

예제1

  1. 예제 1

    입력
    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