#K59352. Maximum Products Storage

    ID: 30845 Type: Default 1000ms 256MiB

Maximum Products Storage

Maximum Products Storage

You are given a warehouse with a number of shelves. Each shelf has a specific capacity, and you have a set of products where each product requires a certain amount of space. Each shelf can store at most one product, and a product can only be placed on a shelf if the shelf's capacity is at least as large as the product's space requirement.

Your task is to determine the maximum number of products that can be stored in the warehouse.

The problem can be formalized as follows: Given an integer \( n \) representing the number of shelves, and a list \( A = [a_1, a_2, \dots, a_n] \) of shelf capacities, as well as an integer \( m \) representing the number of products, and a list \( B = [b_1, b_2, \dots, b_m] \) of the space required by each product, find the maximum number of products that can be stored such that each product is assigned to a distinct shelf \( i \) with \( a_i \ge b_j \) for the product placed at shelf \( i \).

Note: All formulas are given in \( \LaTeX \) format.

inputFormat

The input is given in the following format from standard input:

n
s1 s2 ... sn
m
b1 b2 ... bm

where:

  • \( n \) is the number of shelves.
  • The next line contains \( n \) space-separated integers representing the capacities of the shelves.
  • \( m \) is the number of products.
  • The next line contains \( m \) space-separated integers representing the space required by each product.

outputFormat

Output a single integer representing the maximum number of products that can be stored in the warehouse. The result should be printed to standard output.

## sample
4
10 20 30 40
6
5 10 15 20 25 35
4