#P1462F. The Treasure of The Segments
The Treasure of The Segments
No submission language available for this problem.
Description
Polycarp found segments on the street. A segment with the index is described by two integers and — coordinates of the beginning and end of the segment, respectively. Polycarp realized that he didn't need all the segments, so he wanted to delete some of them.
Polycarp believes that a set of segments is good if there is a segment () from the set, such that it intersects every segment from the set (the intersection must be a point or segment). For example, a set of segments is good, since the segment intersects each segment from the set. Set of segments is not good.
Polycarp wonders, what is the minimum number of segments he has to delete so that the remaining segments form a good set?
The first line contains a single integer () — number of test cases. Then test cases follow.
The first line of each test case contains a single integer () — the number of segments. This is followed by lines describing the segments.
Each segment is described by two integers and () — coordinates of the beginning and end of the segment, respectively.
It is guaranteed that the sum of for all test cases does not exceed .
For each test case, output a single integer — the minimum number of segments that need to be deleted in order for the set of remaining segments to become good.
Input
The first line contains a single integer () — number of test cases. Then test cases follow.
The first line of each test case contains a single integer () — the number of segments. This is followed by lines describing the segments.
Each segment is described by two integers and () — coordinates of the beginning and end of the segment, respectively.
It is guaranteed that the sum of for all test cases does not exceed .
Output
For each test case, output a single integer — the minimum number of segments that need to be deleted in order for the set of remaining segments to become good.