Squarks
Time limit2sMemory limit128 MB
Given the n(n-1)/2 pairwise sums of n distinct positive integers, find and list all sets of n integers whose pairwise sums match these values, in lexicographic order.
- Level
Hard8 of 10
- Topics
- Sorting, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
A physicist named Byteasar is studying squarks, a newly discovered constituent of matter. Squarks are exotic particles that never exist alone but always in pairs, and a squark of one kind only ever pairs with a squark of a different kind.
After years of study he has established that there are different kinds of squarks. Each kind has a unique mass that is a positive integer multiple of some fixed unit. He has also measured the total mass of each of the possible pairs of two different kinds. According to the standard model, the mass of a pair equals the sum of the masses of the two squarks forming it.
Now he wants to determine the individual mass of each kind of squark. Write a program that reconstructs every mass configuration that is consistent with his measurements.
Input
The first line contains an integer (), the number of different kinds of squarks.
The second line contains the total masses of all possible pairs, separated by single spaces. All of them are positive integers, and the mass of each pair does not exceed . For every two different kinds of squarks, the mass of the pair they form is given exactly once, in an arbitrary order.
In tests worth 32% of the points it additionally holds that and the mass of every pair does not exceed 2000.
Output
On the first line print the number of possible solutions. It is guaranteed that at least one solution exists for every input, so .
On each of the following lines print one solution: the distinct positive integer masses of all kinds, in increasing order, separated by single spaces.
So that the answer is uniquely determined, print the solutions in lexicographically increasing order when each is compared as a sequence of integers.