#K14441. Minimum Absolute Subarray Difference

    ID: 24135 Type: Default 1000ms 256MiB

Minimum Absolute Subarray Difference

Minimum Absolute Subarray Difference

You are given an array of integers. Your task is to partition the array into two non-empty contiguous subarrays at some index \(i\) \((1 \leq i < n)\). Let \(S_{left}\) be the sum of the first subarray and \(S_{right}\) be the sum of the second subarray. Find the minimum possible absolute difference between these two sums, i.e., find the minimum value of
\( |S_{left} - S_{right}| \)
where
\( S_{left} = \sum_{j=1}^{i} a_j \) and \( S_{right} = \sum_{j=i+1}^{n} a_j \).

Note: The partition must be made between elements; that is, both subarrays must be non-empty.

inputFormat

The input begins with a single integer \(T\) on the first line, representing the number of test cases. Each test case is described as follows:

  • The first line contains an integer \(n\), the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

For each test case, output a single line containing the minimal absolute difference that can be obtained by splitting the array into two contiguous non-empty parts.

## sample
3
5
1 3 -2 4 6
4
10 -5 3 2
6
-2 2 -3 3 -4 4
0

0 0

</p>