1687: 廊桥分配

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:6 Solved:3

Description

      当一架飞机抵达机场时,可以停靠在航站楼旁的廊桥,也可以停靠在位于机场边缘的远机位。乘客一般更期待停靠在廊桥,因为这样省去了坐摆渡车前往航站楼的周折。然而,因为廊桥的数量有限,所以这样的愿望不总是能实现。
机场分为国内区和国际区,国内航班飞机只能停靠在国内区,国际航班飞机只能停靠在国际区。一部分廊桥属于国内区,其余的廊桥属于国际区。
    L市新建了一座机场,一共有 n个廊桥。该机场决定,廊桥的使用遵循“先到先得”的原则,即每架飞机抵达后,如果相应的区(国内/国际)还有空闲的廊桥,就停靠在廊桥,否则停靠在远机位(假设远机位的数量充足)。该机场只有一条跑道,因此不存在两架飞机同时抵达的情况。

    现给定未来一段时间飞机的抵达、离开时刻,请你负责将 n个廊桥分配给国内区和国际区,使停靠廊桥的飞机数量最多。


Input

输入的第一行,包含三个正整数 lns="http://www.w3.org/1998/Math/MathML">n, m_1, m_2,分别表示廊桥的个数、国内航班飞机的数量、国际航班飞机的数量。

接下来 lns="http://www.w3.org/1998/Math/MathML">m_1 行,是国内航班的信息,第 lns="http://www.w3.org/1998/Math/MathML">i 行包含两个正整数 lns="http://www.w3.org/1998/Math/MathML">a_{1, i}, b_{1, i},分别表示一架国内航班飞机的抵达、离开时刻。

接下来 lns="http://www.w3.org/1998/Math/MathML">m_2 行,是国际航班的信息,第 lns="http://www.w3.org/1998/Math/MathML">i 行包含两个正整数 lns="http://www.w3.org/1998/Math/MathML">a_{2, i}, b_{2, i},分别表示一架国际航班飞机的抵达、离开时刻。

每行的多个整数由空格分隔。

Output

输出一个正整数,表示能够停靠廊桥的飞机数量的最大值。

Sample Input Copy

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

Sample Output Copy

7

HINT

【样例解释】

在图中,我们用抵达、离开时刻的数对来代表一架飞机,如 

lns="http://www.w3.org/1998/Math/MathML">(1, 5) 表示时刻 lns="http://www.w3.org/1998/Math/MathML">1 抵达、时刻 lns="http://www.w3.org/1998/Math/MathML">5 离开的飞机;用 lns="http://www.w3.org/1998/Math/MathML">\surd 表示该飞机停靠在廊桥,用 lns="http://www.w3.org/1998/Math/MathML">\times 表示该飞机停靠在远机位。

我们以表格中阴影部分的计算方式为例,说明该表的含义。在这一部分中,国际区有 lns="http://www.w3.org/1998/Math/MathML">2 个廊桥,lns="http://www.w3.org/1998/Math/MathML">4 架国际航班飞机依如下次序抵达:

  1. 首先 lns="http://www.w3.org/1998/Math/MathML">(2, 11) 在时刻 lns="http://www.w3.org/1998/Math/MathML">2 抵达,停靠在廊桥。
  2. 然后 lns="http://www.w3.org/1998/Math/MathML">(4, 15) 在时刻 lns="http://www.w3.org/1998/Math/MathML">4 抵达,停靠在另一个廊桥。
  3. 接着 lns="http://www.w3.org/1998/Math/MathML">(7, 17) 在时刻 lns="http://www.w3.org/1998/Math/MathML">7 抵达,这时前 lns="http://www.w3.org/1998/Math/MathML">2 架飞机都还没离开、都还占用着廊桥,而国际区只有 lns="http://www.w3.org/1998/Math/MathML">2 个廊桥,所以只能停靠远机位。
  4. 最后 lns="http://www.w3.org/1998/Math/MathML">(12, 16) 在时刻 lns="http://www.w3.org/1998/Math/MathML">12 抵达,这时 lns="http://www.w3.org/1998/Math/MathML">(2, 11) 这架飞机已经离开,所以有 lns="http://www.w3.org/1998/Math/MathML">1 个空闲的廊桥,该飞机可以停靠在廊桥。

根据表格中的计算结果,当国内区分配 lns="http://www.w3.org/1998/Math/MathML">2 个廊桥、国际区分配 lns="http://www.w3.org/1998/Math/MathML">1 个廊桥时,停靠廊桥的飞机数量最多,一共 lns="http://www.w3.org/1998/Math/MathML">7 架。

【数据范围】

对于 lns="http://www.w3.org/1998/Math/MathML">20 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">n \le 100lns="http://www.w3.org/1998/Math/MathML">m_1 + m_2 \le 100
对于 lns="http://www.w3.org/1998/Math/MathML">40 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">n \le 5000lns="http://www.w3.org/1998/Math/MathML">m_1 + m_2 \le 5000
对于 lns="http://www.w3.org/1998/Math/MathML">100 \% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 \le n \le {10}^5lns="http://www.w3.org/1998/Math/MathML">m_1, m_2 \ge 1lns="http://www.w3.org/1998/Math/MathML">m_1 + m_2 \le {10}^5,所有 lns="http://www.w3.org/1998/Math/MathML">a_{1, i}, b_{1, i}, a_{2, i}, b_{2, i} 为数值不超过 lns="http://www.w3.org/1998/Math/MathML">{10}^8 的互不相同的正整数,且保证对于每个 lns="http://www.w3.org/1998/Math/MathML">i \in [1, m_1],都有 lns="http://www.w3.org/1998/Math/MathML">a_{1, i} < b_{1, i},以及对于每个 lns="http://www.w3.org/1998/Math/MathML">i \in [1, m_2],都有 lns="http://www.w3.org/1998/Math/MathML">a_{2, i} < b_{2, i}