#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 chickens on the farm (), conveniently numbered , and each chicken is only willing to help a cow at precisely time . The cows, never in a hurry, have more flexibility in their schedules. There are cows on the farm (), conveniently numbered , where cow is able to cross the road between time and time . Figuring the "buddy system" is the best way to proceed, each cow would ideally like to find a chicken to help her cross the road; in order for their schedules to be compatible, and must satisfy .
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 and . The next lines contain , and the next lines contain and () for . The 's, 's, and '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