Baking Cakes
Time limit1sMemory limit128 MB
Given up to 40 cake baking times and 3 ovens, find the minimum time to bake all cakes.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Greedy, Brute force, Math
- Solved
- No attempts yet
Problem
Tom's birthday is coming up, and you have been put in charge of baking cakes for his enormous birthday party. However, you have a great many cakes to make and very little time, so you are not sure you will even finish before the party!
You are given a list of cakes to make, each requiring a certain amount of time to bake. You have exactly 3 ovens, and each oven can bake only one cake at a time. Assuming that the time required to take one cake out and put another one in is negligible, determine the smallest amount of time you will need to spend baking, given the list of cakes to make.
Input
The input consists of multiple test cases, each on a single line. Each line begins with an integer (where ), the number of cakes to bake. It is followed by integers (where ), the time in minutes required to bake each cake. The end of input is marked by a line containing a single ; do not process this line.
Output
For each test case, output on a single line the smallest amount of time, in minutes, that you need to bake all of your cakes.