A816.Just Stalling--Bronze

普及-

USACO

通过率:0%

时间限制:1.00s

内存限制:128MB

题目描述

Farmer John has NN cows (1N201\le N \leq 20) of heights a1aNa_1 \ldots a_N. His
barn has NN stalls with max height limits b1bNb_1 \ldots b_N (so for example,
if b5=17b_5 = 17, then a cow of height at most 1717 can reside in stall 55). 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?

输入格式

The first line contains NN. The second line contains NN space-separated
integers a1,a2,,aNa_1,a_2,\ldots,a_N. The third line contains NN space-separated
integers b1,b2,,bNb_1,b_2,\ldots,b_N. All heights and limits are in the range
[1,109][1,10^9].

输出格式

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++.

输入输出样例

  • 输入#1

    4
    1 2 3 4
    2 4 3 4
    

    输出#1

    8
    

说明/提示

In this example, we cannot place the third cow into the first stall since
3=a3>b1=23=a_3>b_1=2. Similarly, we cannot place the fourth cow into the first or
third stalls. One way to satisfy the height limits is to assign cow 11 to
stall 11, cow 22 to stall 22, cow 33 to stall 33, and cow 44 to stall
44.

首页