luogu#P7913. [CSP-S 2021] 廊桥分配

    ID: 7267 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>模拟2021O2优化前缀和队列CSP-S 提高级

[CSP-S 2021] 廊桥分配

Problem Description

When an airplane arrives at an airport, it can park at a jet bridge next to the terminal, or at a remote stand on the edge of the airport. Passengers usually prefer parking at a jet bridge, because it saves them the trouble of taking a shuttle bus to the terminal. However, since the number of jet bridges is limited, this wish cannot always be satisfied.

The airport is divided into a domestic area and an international area. Domestic flights can only park in the domestic area, and international flights can only park in the international area. Some jet bridges belong to the domestic area, and the remaining jet bridges belong to the international area.

City LL has built a new airport with a total of nn jet bridges. The airport decides that jet bridge usage follows the “first come, first served” rule: after each airplane arrives, if there is an available jet bridge in the corresponding area (domestic/international), it parks at a jet bridge; otherwise, it parks at a remote stand (assume the number of remote stands is sufficient). The airport has only one runway, so there will not be two airplanes arriving at the same time.

You are given the arrival and departure times of airplanes over a future period. Please allocate the nn jet bridges between the domestic area and the international area so that the number of airplanes that can park at jet bridges is maximized.

Input Format

The first line contains three positive integers n,m1,m2n, m_1, m_2, representing the number of jet bridges, the number of domestic flights, and the number of international flights.

The next m1m_1 lines contain information about domestic flights. The ii-th line contains two positive integers a1,i,b1,ia_{1, i}, b_{1, i}, representing the arrival and departure times of a domestic flight.

The next m2m_2 lines contain information about international flights. The ii-th line contains two positive integers a2,i,b2,ia_{2, i}, b_{2, i}, representing the arrival and departure times of an international flight.

Integers on the same line are separated by spaces.

Output Format

Output one positive integer, the maximum possible number of airplanes that can park at jet bridges.

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

7

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

4

见附件中的 airport/airport3.in
见附件中的 airport/airport3.ans

Hint

[Sample Explanation #1]

In the figure, we use an ordered pair of arrival and departure times to represent a plane. For example, (1,5)(1, 5) means a plane arrives at time 11 and departs at time 55. We use \surd to indicate that the plane parks at a jet bridge, and ×\times to indicate that the plane parks at a remote stand.

We take the shaded part of the table as an example to explain the meaning of the table. In this part, the international area has 22 jet bridges, and 44 international planes arrive in the following order:

  1. First, (2,11)(2, 11) arrives at time 22 and parks at a jet bridge.
  2. Then, (4,15)(4, 15) arrives at time 44 and parks at the other jet bridge.
  3. Next, (7,17)(7, 17) arrives at time 77. At this time, the first 22 planes have not departed and are still occupying the jet bridges. Since the international area has only 22 jet bridges, it can only park at a remote stand.
  4. Finally, (12,16)(12, 16) arrives at time 1212. At this time, the plane (2,11)(2, 11) has already departed, so there is 11 available jet bridge, and this plane can park at a jet bridge.

According to the results in the table, when 22 jet bridges are allocated to the domestic area and 11 jet bridge is allocated to the international area, the number of planes that can park at jet bridges is maximized, with a total of 77 planes.

[Sample Explanation #2]

When 22 jet bridges are allocated to the domestic area and 00 jet bridges are allocated to the international area, the number of planes that can park at jet bridges is maximized, with a total of 44 planes, i.e. all domestic planes can park at jet bridges.

Note that in this problem, jet bridge usage follows the “first come, first served” rule. If the international area has only 11 jet bridge, it will be occupied by the plane (1,19)(1, 19), and it will not be used in turn by the 44 planes (3,4)(3, 4), (5,6)(5, 6), (7,8)(7, 8), (9,10)(9, 10).

[Constraints]

For 20%20\% of the testdata, n100n \le 100, m1+m2100m_1 + m_2 \le 100.
For 40%40\% of the testdata, n5000n \le 5000, m1+m25000m_1 + m_2 \le 5000.
For 100%100\% of the testdata, 1n1051 \le n \le {10}^5, m1,m21m_1, m_2 \ge 1, m1+m2105m_1 + m_2 \le {10}^5. All a1,i,b1,i,a2,i,b2,ia_{1, i}, b_{1, i}, a_{2, i}, b_{2, i} are distinct positive integers with values not exceeding 108{10}^8. It is guaranteed that for each i[1,m1]i \in [1, m_1], a1,i<b1,ia_{1, i} < b_{1, i}, and for each i[1,m2]i \in [1, m_2], a2,i<b2,ia_{2, i} < b_{2, i}.

[Thanks to the providers of hack data]

Translated by ChatGPT 5