#C6614. Minimum Absolute Partition Difference
Minimum Absolute Partition Difference
Minimum Absolute Partition Difference
You are given an array of n integers. Your task is to partition the array into two non-empty subsets such that the absolute difference between the sums of the two subsets is minimized. Formally, let \(S_1\) and \(S_2\) be the two subsets with \(S_1 \cup S_2\) equal to the original set and \(S_1 \cap S_2 = \emptyset\). You need to minimize \( |\sum S_1 - \sum S_2| \).
Note: Each subset must contain at least one element.
Example:
For the array [3, 1, 4, 2]:
Total sum = 10. The optimal partition is [3,2] and [1,4] where both subsets sum to 5, so the minimum absolute difference is 0.
Input/Output Details are explained below.
inputFormat
The first line of input contains an integer \(n\) (\(n \ge 2\)) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.
For example:
4 3 1 4 2
outputFormat
Output a single integer representing the minimum absolute difference between the sums of the two subsets.
For example:
0## sample
4
3 1 4 2
0
</p>