#K37017. Maximum Package Deliveries

    ID: 25883 Type: Default 1000ms 256MiB

Maximum Package Deliveries

Maximum Package Deliveries

You are given n packages, each with a priority level, and m cities, where each city has a limited number of delivery slots. Each slot can deliver exactly one package. The objective is to determine the maximum number of packages that can be delivered in one day if the deliveries are scheduled optimally.

Note that even though each package has a priority, the delivery scheduling is constrained solely by the total number of available slots. In mathematical terms, the maximum number of packages delivered is given by:

\( \min\Big(n,\;\sum_{i=1}^{m} slots_i\Big) \)

where \( n \) is the total number of packages and \( slots_i \) is the number of slots available in the \( i^{th} \) city.

Input is taken from the standard input and output should be written to the standard output.

inputFormat

The input consists of four lines:

  1. An integer n representing the number of packages.
  2. n space-separated integers representing the priority levels of the packages.
  3. An integer m representing the number of cities.
  4. m space-separated integers representing the number of available delivery slots in each city. If m is 0, this line will be present but empty.

outputFormat

Output a single integer which is the maximum number of packages that can be delivered.

## sample
5
1 3 2 5 4
3
2 1 3
5