#K40252. Equal Sum Partition
Equal Sum Partition
Equal Sum Partition
Given a list of integers, determine whether it is possible to partition the list into two non-empty subsets such that the sum of the elements in each subset is equal. In other words, if the total sum of the list is \(S\), each subset should sum to \(\frac{S}{2}\). If such a partition exists, output the two subsets; otherwise, output -1.
The input will be provided from stdin and the output should be sent to stdout. The first line contains an integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated integers.
If a valid partition is found, print the first subset on the first line (elements separated by a single space) and the second subset on the next line. If no valid partition exists, print -1.
Note: Use the standard algorithm to check for the existence of a partition. The solution is expected to check all non-empty proper subsets of the list.
inputFormat
The first line of input is an integer \(n\) denoting the number of elements in the list. The second line contains \(n\) space-separated integers.
Example:
4 1 5 11 5
outputFormat
If a valid partition exists, output two lines: the first line contains the elements of the first subset (space-separated) and the second line contains the elements of the second subset (space-separated). If no partition exists, output a single line with -1.
Example (for the sample input above, a valid output would be):
11 1 5 5## sample
4
1 5 11 5
11
1 5 5
</p>