
Image by Mac, from commons.wikimedia.org
As you often need to do, you are about to hang up your laundry. Having recently moved into a tiny hole of an apartment, you have only two laundry lines, both attached to the same flimsy drying rack, which tips over if one line carries much more weight than the other.
If you start by hanging three shirts on the same line, it might just tip over and you have to start all over again. So you must be careful about the order and manner in which you hang the laundry.
This means you pick up the laundry, one piece at a time, in an order of your choosing, and hang that piece on one of the two lines. Once a piece is hung, it stays where it is.
At any moment, the imbalance is the absolute difference between the total weights on the two lines. You want to hang all the laundry so that the largest imbalance occurring during the process is as small as possible.
Trial and error would be a very wasteful use of time, so now it is time to waste time on making an involved algorithm to take care of it instead.
For example, suppose you have four pieces of laundry, of weights $$$100$$$, $$$120$$$, $$$200$$$, and $$$300$$$ grams. Hanging the $$$300$$$ first gives an imbalance of $$$300$$$ straight away, but you can do better: hang the $$$120$$$ on the first line (imbalance $$$120$$$), then the $$$300$$$ on the second line (imbalance $$$180$$$), then the $$$200$$$ on the first line (imbalance $$$20$$$), and finally the $$$100$$$ on the second line (imbalance $$$80$$$). The largest imbalance during this process is $$$180$$$, which is optimal.
The input consists of:
Output the smallest possible value of the largest imbalance that occurs while hanging up all the laundry.
4200 400 200 100
200
7100 100 900 500 500 1000 400
500
| Name |
|---|


