#C5376. Contiguous Subarray Sum with Minimum Length Constraint
Contiguous Subarray Sum with Minimum Length Constraint
Contiguous Subarray Sum with Minimum Length Constraint
You are given an array of integers \(A\) of length \(n\). Your task is to find the maximum possible sum of any contiguous subarray of \(A\) which has at least 4 elements.
More formally, if we denote a subarray by \(A[i \ldots j]\) where \(0 \le i \le j < n\) and \(j-i+1 \ge 4\), you are to determine the value of
\(\max_{0 \le i \le j < n,\; j-i+1 \ge 4} \sum_{k=i}^{j} A[k]\)
If no valid subarray exists then the answer is defined (by the problem constraints) to always exist. The input guarantees that every test case has at least 4 numbers in its array.
Note: Use \(\LaTeX\) formatting for any mathematical expressions.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- The first line contains a single integer \(T\) representing the number of test cases.
- For each test case:
- The first line contains an integer \(n\) denoting the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array \(A\).
You can assume that \(n \ge 4\) for every test case.
outputFormat
For each test case, output a single integer on a new line, which is the maximum sum of any contiguous subarray with at least 4 elements.
The output should be written to standard output (stdout).
## sample3
5
1 2 3 -2 5
8
-2 -3 4 -1 -2 1 5 -3
8
-1 -2 -3 -4 -5 -6 -7 -8
9
7
-10
</p>