#K57937. Maximum Apples from Three Consecutive Trees
Maximum Apples from Three Consecutive Trees
Maximum Apples from Three Consecutive Trees
You are given an integer n representing the number of trees, and an array of n integers where each integer represents the number of apples on a tree. Your task is to find the maximum sum of apples that can be collected from any three consecutive trees.
Formally, if the number of apples on the trees are \(a_1, a_2, \ldots, a_n\), you need to compute:
\(\max_{1 \leq i \leq n-2} (a_i + a_{i+1} + a_{i+2})\)
You can assume that \(n \ge 3\).
inputFormat
The first line of input contains an integer \(n\) denoting the number of trees.
The second line contains \(n\) space-separated integers representing the number of apples on each tree.
outputFormat
Output a single integer which is the maximum number of apples that can be collected from any three consecutive trees.
## sample5
3 4 5 1 2
12