Editorial for BPC 1 S1 - Homework Questions


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.

Author: BalintR

Subtask 1

We can look at the smallest and largest values in the input and divide both by 2 to get the original numbers.

Subtask 2

We can use the same strategy as in the first subtask to find the smallest and largest elements of the original array. We also know that if we sort the elements in the input, the second element will be the sum of the two smallest elements in the original array.

Subtask 3

The simplest way to solve the full problem is to note that the sum of every ordered pair is added to the list and that each original element is unique. This means that the sum of every pair of distinct numbers is added to the list twice. However, a pair which has the same number twice is only added to the list once. Therefore, we can consider only the numbers that appear an odd number of times in the input, and output each divided by 2.

Time Complexity: \mathcal{O}(N^2 \log N) or \mathcal{O}(N^2)


Comments

There are no comments at the moment.