#K13601. Park Ride Assignment

    ID: 23949 Type: Default 1000ms 256MiB

Park Ride Assignment

Park Ride Assignment

You are given a theme park with a number of rides. Each ride has a specified capacity, and there are several visitors, each with a list of rides they are willing to take. Your task is to determine if it is possible to assign each visitor to exactly one ride according to their preferences without exceeding the given ride capacities.

If every visitor can be assigned to one of their preferred rides, output Yes. Otherwise, output No.

Note: Each visitor is processed in the order of input, and for each, the rides in their preference list are considered in order. The visitor is assigned to the first ride that still has available capacity.

inputFormat

The input is provided from stdin as follows:

  1. The first line contains an integer R, the number of rides.
  2. The second line contains R space-separated integers representing the capacities of each ride.
  3. The third line contains an integer V, the number of visitors.
  4. Each of the following V lines contains a space-separated list of integers. Each line represents the rides a visitor is willing to go on.

outputFormat

Output a single line to stdout containing either Yes if all visitors can be assigned to one of their preferred rides without exceeding capacity, or No otherwise.

## sample
3
2 1 3
4
1 3
1 2
2 3
1 3
Yes