Editorial
Consider a slightly generalized problem: divide the numbers in into three piles with sums , where some may be .
For , the only impossible cases are the following:
- At least two of the are equal to .
- At least two of the are equal to .
A pile with sum must be exactly , and a pile with sum must be exactly , so the cases above are impossible.
We construct the partition by placing the numbers from large to small. Suppose we are currently processing . If the remaining target sums are , placing into pile changes the remaining sum of that pile to . Try all piles where this is nonnegative, and choose one that keeps the remaining instance on feasible by the condition above.
Starting from a feasible state, such a choice always exists. Therefore, repeating this for gives a valid partition.
If the initial state is impossible, print . Otherwise, output the three piles obtained by the construction.
Solution written by GPT5.5