#K68647. Minimum Absolute Difference of Sums

    ID: 32911 Type: Default 1000ms 256MiB

Minimum Absolute Difference of Sums

Minimum Absolute Difference of Sums

Alex is given a list of N positive integers and his task is to partition these integers into two non-empty subsets so that the absolute difference of their sums is minimized. Formally, let the two subsets have sums S1 and S2 respectively. You need to minimize:

\( |S_1 - S_2| = |(\text{total sum} - 2S_1)| \)

Your program should process multiple test cases. For each test case, compute and output the minimum absolute difference.

inputFormat

The first line contains an integer T representing the number of test cases.

For each test case:

  • The first line contains an integer N, the number of integers.
  • The second line contains N space-separated positive integers.

Input is read from standard input.

outputFormat

For each test case, output a single line containing the minimum possible absolute difference between the sums of the two subsets.

Output is written to standard output.

## sample
2
4
1 6 11 5
3
7 2 4
1

1

</p>