Editorial for COCI '12 Contest 6 #2 Sume


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

We will leave the case N = 2 as a practice to the reader. If N is at least 3, observe the first three (unknown for now) elements of the array and their mutual sums (read from the matrix):

\displaystyle \begin{align*}
a+b &= s_1 \\
b+c &= s_2 \\
c+a &= s_3
\end{align*}

Summing these equations we get 2a+2b+2c = s_1+s_2+s_3, and then a+b+c = (s_1+s_2+s_3)/2.

Now a = (a+b+c)-(b+c) = (s_1+s_2+s_3)/2-s_2.

Knowing the first element of the array, we easily determine the others: i^\text{th} element is equal to the sum of the first and i^\text{th} element (this sum is read from the matrix) decreased by the first element.

If we want to avoid the above mentioned math, limitations for the elements given in the task allow us to try all possible values for the first element of the array. For each of these possibilities, we generate other elements of the array as shown in the previous paragraph and test the correctness of the array by summing any two elements different from the first. The question of why it works is left as an exercise to the reader.

For practice, consider this task where the cases that there is no solution or that there are infinitely many solutions are possible and to be detected.


Comments

There are no comments at the moment.