#K10431. Maximum Product of Array Splitting
Maximum Product of Array Splitting
Maximum Product of Array Splitting
You are given an array of integers. Your task is to split this array into two non-empty subarrays at a point such that the product of the sums of the two subarrays is maximized. Formally, if the array is A of length N and you split it at position i (where 1 ≤ i < N), let SL = \(\sum_{j=0}^{i-1} A[j]\) and SR = \(\sum_{j=i}^{N-1} A[j]\). You need to maximize the product \(S_L \times S_R\). If the array cannot be split into two non-empty subarrays (i.e. when N < 2), output -1
.
Note: There may be several ways to split the array. You only need to output the maximum product of the sums.
inputFormat
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 elements of the array.
Input is given from standard input (stdin).
outputFormat
For each test case, output a single line containing the maximum product of the sums of the two non-empty subarrays. If the array cannot be split, output -1
.
Output should be written to standard output (stdout).
## sample4
5
1 2 3 4 5
3
1 1 1
4
10 5 1 2
1
1
54
2
80
-1
</p>