#K71667. Maximum Fruit from Three Consecutive Trees
Maximum Fruit from Three Consecutive Trees
Maximum Fruit from Three Consecutive Trees
You are given trees in a row, where each tree produces a certain amount of fruits. The fruits produced by the -th tree is denoted by with , and you have to find the maximum total amount of fruits that can be collected by selecting any three consecutive trees. Note that satisfies . For example, if and the fruits array is [4, 2, 3, 7, 1], then the maximum sum is . Read the input from standard input (stdin) and output the result to standard output (stdout).
inputFormat
The input consists of two lines. The first line contains an integer , the number of trees. The second line contains space-separated integers representing the number of fruits produced by each tree.
outputFormat
Output a single integer which is the maximum total amount of fruits that can be collected from any three consecutive trees.## sample
5
4 2 3 7 1
12
</p>