#K58672. Maximal Gold Collection
Maximal Gold Collection
Maximal Gold Collection
You are given several test cases. In each test case, you are provided with an integer n representing the number of gold piles and a sequence of n integers which indicate the amount of gold present in each pile.
Your task is to choose three consecutive gold piles such that the sum of gold from these three piles is maximized. Formally, if the gold piles are given by \( a_1, a_2, \dots, a_n \), you need to compute:
\( \max_{1 \leq i \leq n-2} (a_i + a_{i+1} + a_{i+2}) \)
Output the maximal sum for each test case.
Note: It is guaranteed that \( n \geq 3 \) for each test case.
inputFormat
The input begins with an integer T indicating the number of test cases. Each test case is described as follows:
- The first line of each test case contains an integer n (\( n \geq 3 \)) representing the number of gold piles.
- The second line contains n space-separated integers, where the \( i^{th} \) integer represents the amount of gold in the \( i^{th} \) pile.
For example:
1 4 1 2 3 4
outputFormat
For each test case, output a single line containing the maximal sum of gold that can be collected by choosing three consecutive piles.
For the above input, the output should be:
9## sample
1
4
1 2 3 4
9
</p>