Time Limit: 8 sec / Memory Limit: 256 MB
Problem
Wolf Sothe owns a long land in the jungle. In this linear land, trees grow at regular intervals. The size of the tree from one end is given as .
Inside the jungle it is dark because trees obstruct sunlight. In order to let sunlight shine into the jungle, Wolf Sothe considers cutting some of the trees (or cutting no one). More specifically, trees will be cut with the following rules.
- Up to trees can be cut (no more than ).
- Considering the impact on the surrounding ecosystem, it is not allowed to cut two or more trees in arbitrary consecutive trees. More precisely, there is not such that or more trees are cut in the , , ......, trees from one end.
- If Wolf Sothe cuts the tree from one end, the size of the tree becomes .
- We want the maximum value of the sum of sizes of consecutive trees to be as small as possible. Namely, we want to minimize
.
Since the size of the trees and , have been given, when we make the optimal cutting choice for the trees, please obtain the minimum value of the maximum value of the sum of sizes of consecutive trees.
Input
Inputs will be given by standard input in following format.
:
- At the first line, integer , , will be given.
- From the second line there are additional lines to give information about sizes of trees. At the line, integer will be given.
Output
Please print the minimum value of the maximum value of the sum of sizes of consecutive trees, when we made the optimal cutting choice for the trees in a line.
Print a newline at the end of output.
Input Example 1Copy
6 2 3 1 5 6 2 4 3
Output Example 1Copy
7
If Wolf Sothe cuts the and tree, the minimum value of the maximum value of the sum of sizes of consecutive consecutive trees will be obtained when it is for the , , tree. The sum of sizes is .
Input Example 2Copy
10 3 4 3 14 1 5 9 2 6 5 3 5
Output Example 2Copy
17