Editorial for COCI '12 Contest 6 #2 Sume
Submitting an official solution before solving the problem yourself is a bannable offence.
We will leave the case as a practice to the reader. If is at least , observe the first three (unknown for now) elements of the array and their mutual sums (read from the matrix):
Summing these equations we get , and then .
Now .
Knowing the first element of the array, we easily determine the others: element is equal to the sum of the first and 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