Editorial for Mock CCC '20 Contest 1 J4 - A Binary Problem


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.

For 5 marks, a quadratic brute force suffices.

For full credit, imagine sweeping over the houses from left-to-right and from right-to-left, tracking the minimum distance to a house in that direction. The answer is therefore the sum of the minimum of these two values at each index. Be careful of overflow.


Comments

There are no comments at the moment.