Editorial for COCI '11 Contest 1 #1 Jabuke


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.

Movements of the boat can be simulated by keeping track of the leftmost and rightmost column occupied by the boat.

If the apple is falling down a column between those two columns (inclusive), we do not need to move the boat.

Otherwise, if the apple is falling to the left of the boat, we can move the boat just enough to catch the apple - the boat's leftmost column needs to align with the apple's column. The new positions are simple to calculate: the leftmost column is set to the apple's column; the distance that the boat has moved is equal to the difference of the old and new leftmost column positions, and the rightmost column also moves that same distance to the left.

If the apple is falling to the right of the boat, we apply a completely analogous move. In the end, we just output the sum of all move distances.


Comments

There are no comments at the moment.