#K9466. Maximum Final Element Sum
Maximum Final Element Sum
Maximum Final Element Sum
Problem Statement:
You are given an array of integers and you are allowed to perform the following operation any number of times: choose two adjacent elements and replace both with their sum. Eventually, after performing these operations repeatedly, the array will be reduced to a single element. Your task is to compute the maximum possible value of the final element.
Observation:
No matter how you combine the elements, the final value is simply the sum of the initial array elements. Formally, for an array \( A = [A_1, A_2, \dots, A_n] \), the maximum final element is
$$ S = \sum_{i=1}^{n} A_i. $$
Read the input from standard input and output the result for each test case to standard output.
inputFormat
Input Format:
The input is read from stdin
. The first line contains an integer T, the number of test cases. Each test case consists of two lines:
- The first line of a test case contains an integer n denoting the number of elements in the array.
- The second line contains n space-separated integers representing the array elements.
outputFormat
Output Format:
For each test case, output a single line containing the maximum possible value of the final element (i.e. the sum of the array elements) to stdout
.
3
3
1 2 3
4
4 5 1 3
2
10 20
6
13
30
</p>