#P3661. Cow-Chicken Pairing Problem
Cow-Chicken Pairing Problem
Cow-Chicken Pairing Problem
Farmer John's cows are trying to learn to cross the road effectively. Inspired by the old "why did the chicken cross the road?" joke, the cows believe that chickens are experts at road crossing. However, chickens have very tight schedules. There are \(C\) chickens (\(1 \leq C \leq 20,000\)), numbered from 1 to \(C\), where chicken \(i\) is only available at exactly time \(T_i\). Meanwhile, there are \(N\) cows (\(1 \leq N \leq 20,000\)), numbered from 1 to \(N\), and cow \(j\) can cross the road only during the time interval \([A_j, B_j]\). A cow and a chicken can form a pair if and only if \(A_j \leq T_i \leq B_j\). Each cow and each chicken can be paired at most once. The goal is to compute the maximum number of cow-chicken pairs that can be formed.
inputFormat
The first line contains two integers \(C\) and \(N\): the number of chickens and the number of cows, respectively. The next \(C\) lines each contain an integer \(T_i\) representing the time at which chicken \(i\) is available. The following \(N\) lines each contain two integers \(A_j\) and \(B_j\) representing the start and end times during which cow \(j\) can cross the road.
outputFormat
Output a single integer representing the maximum number of cow-chicken pairs that can be formed.
sample
2 2
5
10
4 6
10 15
2
</p>