题目描述
Problem Description
Takahashi and Aoki have planned a speed dating event. They have successfully gathered $N$ men and $M$ women. The men are numbered from $1$ to $N$, and the women are numbered from $1$ to $M$. As the organizers, Takahashi and Aoki aim to maximize the number of couples formed during this event. Here, a couple refers to a pair of one man and one woman, and no individual can be part of more than one couple.
The $i$-th man ($1 \leq i \leq N$) has an annual income of $A_i$ yen and wishes to form a couple with a woman whose annual income is at least $B_i$ yen. The $j$-th woman ($1 \leq j \leq M$) has an annual income of $C_j$ yen and wishes to form a couple with a man whose annual income is at least $D_j$ yen.
Takahashi and Aoki can form a couple between the $i$-th man and the $j$-th woman if and only if both their requirements are met, i.e., $B_i \leq C_j$ and $D_j \leq A_i$.
Your task is to determine the maximum number of couples that can be formed during this speed dating event.
Input Format
The input is given from the standard input in the following format:
$N$ $M$ $A_1$ $B_1$ $A_2$ $B_2$ : $A_N$ $B_N$ $C_1$ $D_1$ $C_2$ $D_2$ : $C_M$ $D_M$
- The first line contains two integers $N, M$ ($1 \leq N, M \leq 150,000$), representing the number of men and women, respectively.
- The next $N$ lines, where the $i$-th line ($1 \leq i \leq N$) contains two integers $A_i, B_i$ ($1 \leq A_i, B_i \leq 10^9$), representing the annual income and the required annual income of the $i$-th man.
- The next $M$ lines, where the $j$-th line ($1 \leq j \leq M$) contains two integers $C_j, D_j$ ($1 \leq C_j, D_j \leq 10^9$), representing the annual income and the required annual income of the $j$-th woman.
Output Format
Output the maximum number of couples that can be formed during this speed dating event in one line. End the output with a newline.
Sample Input and Output
Sample Input #1
3 3
3 5
2 4
4 5
3 1
6 2
5 3
Sample Output #1
2
Sample Input #2
3 4
4 1
2 1
7 1
5 3
12 1
1 10
8 5
Sample Output #2
3
Sample Input #3
5 1
1 1
1 1
1 1
1 1
1 1
1 1
Sample Output #3
1
Sample Input #4
1 1
1 1
1 2
Sample Output #4
0
Notes/Hints
Partial Points
This problem has partial points.
- If you solve the dataset where for any $i, j$ ($1 \leq i \leq N, 1 \leq j \leq M$), $B_i \leq C_j$ is satisfied, you will be awarded 30 points.
Sample Explanation 1
- Forming a couple between the 1st man and the 2nd woman, and between the 2nd man and the 3rd woman results in the maximum number of couples, which is 2.
- Note that no individual can be part of multiple couples.
- This case does not satisfy the additional constraint for partial points since there exists a case where the required income of a man is greater than the woman's income.
Sample Explanation 2
- Forming couples between the 1st man and the 1st woman, the 2nd man and the 2nd woman, and the 3rd man and the 4th woman results in the maximum number of couples, which is 3.
- This case satisfies the additional constraint for partial points.
Sample Explanation 3
- This case satisfies the additional constraint for partial points.
Sample Explanation 4
- Note that the number of formed couples can be 0.
- This case satisfies the additional constraint for partial points.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分