#P4995. [Usaco2017 Feb]Why Did the Cow Cross the Road

[Usaco2017 Feb]Why Did the Cow Cross the Road

题目描述

Farmer John's cows are trying to learn to cross the road effectively. Remembering the old "why did the chicken cross the road?" joke, they figure the chickens must be experts on crossing the road, and go off in search of chickens to help them.

As it turns out, chickens are very busy creatures and have limited time to help the cows. There are CC chickens on the farm (1C20,0001 \leq C \leq 20,000), conveniently numbered 1C1 \ldots C, and each chicken ii is only willing to help a cow at precisely time TiT_i. The cows, never in a hurry, have more flexibility in their schedules. There are NN cows on the farm (1N20,0001 \leq N \leq 20,000), conveniently numbered 1N1 \ldots N, where cow jj is able to cross the road between time AjA_j and time BjB_j. Figuring the "buddy system" is the best way to proceed, each cow jj would ideally like to find a chicken ii to help her cross the road; in order for their schedules to be compatible, ii and jj must satisfy AjTiBjA_j \leq T_i \leq B_j.

If each cow can be paired with at most one chicken and each chicken with at most one cow, please help compute the maximum number of cow-chicken pairs that can be constructed.

输入格式

The first line of input contains CC and NN. The next CC lines contain T1TCT_1 \ldots T_C, and the next NN lines contain AjA_j and BjB_j (AjBjA_j \leq B_j) for j=1Nj = 1 \ldots N. The AA's, BB's, and TT's are all non-negative integers (not necessarily distinct) of size at most 1,000,000,000

输出格式

Please compute the maximum possible number of cow-chicken pairs.

样例 #1

样例输入 #1

5 4
7
8
6
2
9
2 5
4 9
0 3
8 13

样例输出 #1

3