cho.sh
Notes
Loading...

Cargo Loading

Time limit

2s

Memory limit

128 MB

Problem

Jimin works at a harbor and needs to load several boxes onto a cargo ship. There are N cranes at the harbor, and each crane can load one box per minute. All cranes can work at the same time.

Each crane has a weight limit. A crane cannot move a box that is heavier than its limit. Find the minimum time needed to load every box onto the ship.

Input

The first line contains N, the number of cranes. N is a positive integer no greater than 50.

The second line contains the weight limits of the N cranes. Each limit is a positive integer no greater than 1,000,000.

The third line contains M, the number of boxes. M is a positive integer no greater than 10,000.

The fourth line contains the weights of the M boxes. Each weight is a positive integer no greater than 1,000,000.

Output

Print the minimum number of minutes needed to load all boxes onto the ship. If it is impossible to load every box, print -1.