Time limit
2s
Memory limit
128 MB
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.
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.
Print the minimum number of minutes needed to load all boxes onto the ship. If it is impossible to load every box, print -1.