QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#1768. Jet Bridge Allocation

统计

When an airplane arrives at an airport, it can either dock at a boarding bridge next to the terminal or park at a remote stand on the edge of the airport. Passengers generally prefer docking at a boarding bridge because it saves them the trouble of taking a shuttle bus to the terminal. However, because the number of boarding bridges is limited, this wish cannot always be fulfilled.

The airport is divided into a domestic zone and an international zone. Domestic flights can only dock in the domestic zone, and international flights can only dock in the international zone. Some boarding bridges belong to the domestic zone, and the rest belong to the international zone.

City L has built a new airport with a total of $n$ boarding bridges. The airport has decided that the use of boarding bridges will follow a "first-come, first-served" principle: after each airplane arrives, if there is a free boarding bridge in the corresponding zone (domestic/international), it will dock at the boarding bridge; otherwise, it will park at a remote stand (assuming there are sufficient remote stands). The airport has only one runway, so there is no situation where two airplanes arrive at the same time.

Given the arrival and departure times of airplanes for a future period, you are responsible for allocating the $n$ boarding bridges to the domestic and international zones to maximize the total number of airplanes that can dock at boarding bridges.

Input

The first line contains three positive integers $n, m_1, m_2$, representing the number of boarding bridges, the number of domestic flights, and the number of international flights, respectively.

The next $m_1$ lines contain information about domestic flights. The $i$-th line contains two positive integers $a_{1,i}, b_{1,i}$, representing the arrival and departure times of a domestic flight.

The next $m_2$ lines contain information about international flights. The $i$-th line contains two positive integers $a_{2,i}, b_{2,i}$, representing the arrival and departure times of an international flight.

Multiple integers on each line are separated by spaces.

Output

Output a single positive integer representing the maximum number of airplanes that can dock at boarding bridges.

Examples

Input 1

3 5 4
1 5
3 8
6 10
9 14
13 18
2 11
4 15
7 17
12 16

Output 1

7

Note 1

In the figure, we use pairs of arrival and departure times to represent an airplane, such as $(1, 5)$ representing an airplane that arrives at time $1$ and departs at time $5$; $\checkmark$ indicates that the airplane docks at a boarding bridge, and $\times$ indicates that the airplane parks at a remote stand.

Taking the shaded part of the table as an example to explain the meaning of the table: in this part, the international zone has $2$ boarding bridges, and $4$ international flights arrive in the following order: 1. First, $(2, 11)$ arrives at time $2$ and docks at a boarding bridge. 2. Then, $(4, 15)$ arrives at time $4$ and docks at another boarding bridge. 3. Next, $(7, 17)$ arrives at time $7$. At this time, the first $2$ airplanes have not yet departed and are still occupying the boarding bridges. Since the international zone only has $2$ boarding bridges, it must park at a remote stand. 4. Finally, $(12, 16)$ arrives at time $12$. At this time, the airplane $(2, 11)$ has already departed, so there is $1$ free boarding bridge, and the airplane can dock at the boarding bridge.

According to the calculation results in the table, when $2$ boarding bridges are allocated to the domestic zone and $1$ boarding bridge is allocated to the international zone, the number of airplanes docking at boarding bridges is maximized, totaling $7$ airplanes.

Input 2

2 4 6
20 30
40 50
21 22
41 42
1 19
2 18
3 4
5 6
7 8
9 10

Output 2

4

Note 2

When $2$ boarding bridges are allocated to the domestic zone and $0$ boarding bridges are allocated to the international zone, the number of airplanes docking at boarding bridges is maximized, totaling $4$ airplanes, meaning all domestic flights can dock at boarding bridges.

It should be noted that the use of boarding bridges in this problem follows the "first-come, first-served" principle. If the international zone has only $1$ boarding bridge, it will be occupied by the airplane $(1, 19)$ and will not be used sequentially by the $4$ airplanes $(3, 4), (5, 6), (7, 8), (9, 10)$.

Examples 3

See airport/airport3.in and airport/airport3.ans in the contestant's directory.

Constraints

For $20\%$ of the data, $1 \le n \le 100, 1 \le m_1 + m_2 \le 100$. For $40\%$ of the data, $1 \le n \le 5000, 1 \le m_1 + m_2 \le 5000$. For $100\%$ of the data, $1 \le n \le 100000, 1 \le m_1 + m_2 \le 100000$. All $a_{1,i}, b_{1,i}, a_{2,i}, b_{2,i}$ are distinct positive integers not exceeding $10^8$. It is guaranteed that $\forall i \in [1, n], a_{1,i} < b_{1,i}, a_{2,i} < b_{2,i}$.

Figure 1. Table illustrating the boarding bridge allocation and the resulting number of docked airplanes for the example.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.