#P9942. [USACO21JAN] Just Stalling B
[USACO21JAN] Just Stalling B
Problem Description
Farmer John has cows () with heights . His barn has stalls, with height limits (for example, if , then a cow of height at most can live in stall ). How many different ways can Farmer John assign his cows so that each cow lives in a different stall and every stall’s height limit is satisfied?
Input Format
The first line contains . The second line contains space-separated integers . The third line contains space-separated integers . All heights and height limits are in the range .
Output Format
Output the number of ways Farmer John can assign each cow to a different stall such that every stall’s height limit is satisfied. Note that the answer may require a 64-bit integer type, such as long long in C++.
4
1 2 3 4
2 4 3 4
8
Hint
Sample Explanation 1
In this example, we cannot assign the third cow to the first stall because . Similarly, we cannot assign the fourth cow to the first or third stall. One valid assignment that satisfies the height limits is to put cow 1 in stall 1, cow 2 in stall 2, cow 3 in stall 3, and cow 4 in stall 4.
Test Point Properties
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5