Pero the Baker
Time limit1sMemory limit64 MB
Assign loaves of P sizes to P ovens so all finish as fast as possible; each round bakes everything in an oven and takes five minutes.
- Level
Medium6 of 10
- Topics
- Greedy, Binary search, Implementation
- Solved
- No attempts yet
Problem
Pero the baker has taken over a bakery, and he bakes bread in his ovens.
The loaves come in several sizes, and so do the ovens. The ovens are numbered , where oven 1 is the largest, oven 2 is the second largest, and each next oven is smaller. The largest loaves fit only in oven 1, the next size down fits in ovens 1 and 2, and the smallest loaves fit in every oven, including oven .
Several loaves can bake in one oven at the same time. Oven holds at most loaves at once, no matter what their sizes are. Each loaf still has to be small enough to fit in that oven. All ovens run at the same time.
Pero has to bake loaves that fit only in oven 1 (the largest loaves), loaves that fit in ovens 1 and 2, and so on down to loaves that fit in every oven.
An oven takes five minutes to bake everything inside it. Find the smallest amount of time Pero needs to bake all of the loaves.
Input
The first line contains the number of ovens (). The loaves come in sizes as well.
The second line contains natural numbers , each at most . The number is how many loaves can be baked in oven or in any larger oven.
The third line contains natural numbers , each at most . The number is how many loaves oven can bake at once.
Output
Print on the first line the smallest baking time in minutes.
Hint
A single oven with capacity 3 needs three rounds to bake 7 loaves. It bakes 3 loaves in each of the first two rounds and 1 loaf in the last one, so it takes 15 minutes.