Bale Share
InterviewTime limit1sMemory limit128 MB
Assign N bales (N up to 20) to three barns so the largest barn total is as small as possible, and print that smallest possible largest total.
- Level
Medium4 of 10
- Topics
- Brute force, Recursion, Backtracking, Math
- Solved
- No attempts yet
Problem
Farmer John has just received a new shipment of () bales of hay, where bale has size (). He wants to divide the bales among his three barns as fairly as possible.
Farmer John decides that a fair division is one that makes the largest share as small as possible. Formally, if , , and are the total sizes of the bales placed in barns 1, 2, and 3 respectively, ordered so that , then he wants to be as small as possible.
Each bale cannot be split and must be placed in exactly one barn. A barn may be left empty (total size 0).
Determine the value of in a fair division.
Input
The first line contains the number of bales, .
Each of the next lines contains one integer: the -th of these lines gives , the size of the -th bale.
Output
Print the value of in a fair division on a single line.