#K77152. Minimum Subset Sum Difference

    ID: 34801 Type: Default 1000ms 256MiB

Minimum Subset Sum Difference

Minimum Subset Sum Difference

Given a set of positive integers, partition it into two subsets such that the absolute difference between the sums of the two subsets is minimized. In other words, if S is the sum of all elements, you need to find a subset that minimizes the value \(|S - 2\times s|\), where \(s\) is the sum of the chosen subset.

Your task is to compute this minimum difference.

Note: The problem requires you to design a solution that reads from standard input and outputs to standard output.

inputFormat

The input is given via standard input. The first line contains an integer T, the number of test cases. Each test case consists of a single line: the first integer is N denoting the number of elements, followed by N space-separated positive integers.

Example:

2
4 1 6 11 5
3 1 2 3

outputFormat

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

Example:

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

0

</p>