Editorial for Baltic OI '09 - Beetle
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Let's start off by adding the number 0
to our list of integer coordinates. This is the starting coordinate and we will treat it as a dew drop. Now consider the list as the sorted list of integer coordinates and say
is the size of our new list.
The approach begins with the observation that the drops of dew the beetle will drink in the most optimal solution will always be a continuous segment of our list. Because it takes no time for the beetle to drink a drop of dew, drinking a drop of dew at position means the beetle should drink all the drops en route from
to
in order to maximize the amount of water drank.
Given this, we define to be the lowest cost to drink
drops of dew after drinking all the water from the range
. Note this value does not include the cost to drink the drops in the range
. The lowest cost is defined as the cumulative water lost across all
drops of dew.
However, does not account for the position of the beetle at this state (it may be at position
or
). Thus, we define
to be
with the beetle at position
, while
is to be
with the beetle at position
.
The base case is , as it takes
cost to drink
drops of dew.
The transition is then .
is the cost required to get from
to
, and can be found through the formula
. This is due to each of the
drops of dew losing a unit of water for each unit of distance travelled.
uses the same formula but with the points
and
.
Likewise, , where
involves the points
and
, and
involves the points
and
.
The final answer can be found by taking the maximum over all , where
is the index of
0
in , and
. This works because the range defined in
is
, which means we consider
as already drunk before the bug drinks
more drops. The formula itself subtracts the cumulative water lost across all
drops of dew (see paragraph 3) from the total water initially available:
.
Comments