Mizuyokan
InterviewTime limit2sMemory limit512 MB
Given a bar divided by N-1 score lines into segments of given lengths, cut along some lines so the longest and shortest resulting pieces differ as little as possible.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Binary search, Prefix sum, Greedy
- Solved
- No attempts yet
Problem
Mizuyokan is a Japanese sweet made by pouring a paste of red beans into a mould and setting it with agar. JOI has one bar of mizuyokan shaped like a long rectangular block. He plans to eat it as today's snack.
The bar carries score lines that run across it. The whole bar has length , and the -th score line sits at distance from the left end.
The bar is too large to eat whole, so JOI picks at least one of the score lines and cuts the bar along every picked line, splitting it into several pieces. Pieces of uneven size look bad, so he wants the difference between the longest piece and the shortest piece to be as small as possible.
Find the smallest possible difference between the length of the longest piece and the length of the shortest piece.
Input
The input is given from standard input in the following format.
N
L_1
L_2
...
L_N
The first line has the number of blocks . Each of the next lines has on the -th of them.
Output
Print the smallest possible difference between the longest piece and the shortest piece on one line.
Constraints
- Every input value is an integer.