#5115. Problem 3. Just Stalling
Problem 3. Just Stalling
Problem 3. Just Stalling
USACO 2021 January Contest, Bronze
Farmer John has cows () of heights . His barn has stalls with max height limits (so for example, if , then a cow of height at most can reside in stall ). In how many distinct ways can Farmer John arrange his cows so that each cow is in a different stall, and so that the height limit is satisfied for every stall?
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains . The second line contains space-separated integers . The third line contains space-separated integers . All heights and limits are in the range .
OUTPUT FORMAT (print output to the terminal / stdout):
The number of ways Farmer John can place each cow into a different stall such that the height limit is satisfied for every stall. Note that the large size of the output might require the use of a 64-bit integer, like a "long long" in C++.
SAMPLE INPUT:
4 1 2 3 4 2 4 3 4
SAMPLE OUTPUT:
8
In this example, we cannot place the third cow into the first stall since . Similarly, we cannot place the fourth cow into the first or third stalls. One way to satisfy the height limits is to assign cow to stall , cow to stall , cow to stall , and cow to stall .
SCORING: Test cases 1-5 satisfy .Test cases 6-12 satisfy no additional constraints.
Problem credits: Shreyas Thumathy