#P9942. Cow Barn Assignment
Cow Barn Assignment
Cow Barn Assignment
Farmer John has \(N\) cows with heights \(a_1, a_2, \ldots, a_N\) and \(N\) barns with height limits \(b_1, b_2, \ldots, b_N\). A cow with height \(a_i\) can be assigned to barn \(j\) only if \(a_i \le b_j\). Each barn must house exactly one cow and every cow must be assigned to a barn. Compute the number of different assignments that satisfy the barns' height restrictions.
Input Format: The first line contains an integer \(N\) \( (1 \le N \le 20) \). The second line contains \(N\) integers representing the cow heights \(a_1, a_2, \ldots, a_N\). The third line contains \(N\) integers representing the barn limits \(b_1, b_2, \ldots, b_N\).
Output Format: Output a single integer which is the number of valid assignments.
Note: All formulas are in \(\LaTeX\) format.
inputFormat
The input begins with an integer \(N\). The next line contains \(N\) space-separated integers \(a_1, a_2, \ldots, a_N\) denoting the heights of the cows. The following line contains \(N\) space-separated integers \(b_1, b_2, \ldots, b_N\) denoting the height limits of the barns.
outputFormat
Output one integer: the number of valid ways to assign the cows to the barns so that each barn's height limit is respected.
sample
3
1 2 3
3 3 3
6