#K67592. Minimal Partition of a List
Minimal Partition of a List
Minimal Partition of a List
Given a list of non‐negative integers, partition the list into exactly two non‐empty sublists such that the absolute difference between the sums of the two sublists is minimized. Formally, if the total sum is \(T\) and one subset sums to \(S\), then the goal is to minimize \(|2S - T|\). Dynamic programming techniques are encouraged to solve this problem.
The input starts with an integer \(n\) (with \(n \ge 2\)), indicating the number of elements, followed by \(n\) integers separated by spaces. The output should consist of two lines: the first line prints the elements of the first subset, and the second line prints the elements of the second subset. Both subsets must be non-empty and together contain all the numbers.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) (\(n \ge 2\)), representing the number of elements.
- The second line contains \(n\) non-negative integers separated by spaces.
outputFormat
Output two lines:
- The first line contains the elements of the first subset, separated by spaces.
- The second line contains the elements of the second subset, separated by spaces.
The two subsets must be non-empty and represent a partition of the input list that minimizes the absolute difference between their sums.
## sample4
1 6 11 5
6 5
1 11
</p>