Home STD Contest Notification Clarification Problems Ranklist Status Print Sign Out

Horizontal and Vertical Rays

Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 114    Accepted Submission(s): 41


Problem Description
There are H horizontal rays and V vertical rays. A horizontal ray is a straight line which originates at some point and extends infinitely far to the right (towards increasing X coordinates). A vertical ray is a straight line which originates at some point and extends infinitely far down (towards decreasing Y coordinates). A horizontal ray whose origin is (Xh,Yh) touches a vertical ray whose origin is (Xv,Yv) if Xh<=Xv and Yh<=Yv.
You must choose a subset S consisting of the minimum number of vertical rays such that each horizontal ray is touched by at least one vertical ray in S. It is guaranteed that it will always be possible to choose such a subset for the given test data.
 

Input
The first line of input contains an integer number T, representing the number of test cases to follow. The first line of each test case contains 2 integer numbers: H (1<=H<=100.000) and V (1<=V<=100.000). The next H lines contain 2 integers each: X and Y, representing the (X,Y) coordinates of the origins of the horizontal rays. The next V lines contain 2 integers each: X and Y, representing the (X,Y) coordinates of the origins of the vertical rays. All the X and Y coordinates in the input are in the range 0 ... 50.000.000.
 

Output
For each of the T test cases, in the order given in the input, print one line containing the minimum number of vertical rays chosen.
 

Sample Input
1 3 3 1 6 4 4 6 2 3 8 5 7 9 4
 

Sample Output
2
 

Author
Mugurel Ionut Andreica
 

Hint

The solution might consist of the second and third vertical rays. Another solution could be formed by the first and the third vertical rays.


 

Statistic | Submit | Clarifications | Back