#K95297. Minimum Difference Partition
Minimum Difference Partition
Minimum Difference Partition
John is an avid collector of antique coins. He has a collection of n coins, each with a known value. John wishes to divide his coins into two groups such that the absolute difference between the total values of the two groups is minimized.
Let \(S\) be the sum of all coin values and \(s\) be the sum of coins in one group. The goal is to minimize the difference given by:
$$\text{difference} = |(S - s) - s|.$$Your task is to compute this minimum possible difference.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer n (the number of coins).
- The second line contains n space-separated integers representing the value of each coin.
outputFormat
Output the minimum possible absolute difference between the sums of the two groups to standard output (stdout).
## sample4
1 2 3 4
0
</p>