Capba dreams of one day being a virtuoso trombone soloist… but for
now, he must practice his boring exercises, which involve playing
Since he wants to save his energy for more interesting things, he wants
to get through the exercise with as little effort as possible. Most
importantly, this means minimizing the total distance that the slide
moves. If two consecutive notes are played in positions
However, if there are multiple ways to play the exercise which minimize
the movement of the slide, Capba wants the one which will minimize the
number of times the slide must change direction – another important
aspect which can reduce the amount of effort. Between two consecutive
notes, with the first played in slide position
Given the above criteria, your job is to find a way to play all of the notes in order that minimizes the effort required, and output the total distance travelled by the slide as well as the number of times it changes direction.
Input Specification
Line
Next
Output Specification
Output two space-separated integers: the total distance travelled by the slide, followed by the number of direction changes, for the best solution.
Sample Input
8
2 1 6
2 3 6
2 1 4
2 3 6
2 1 5
2 2 6
1 4
2 6 1
Sample Output
10 2
Explanation for Sample Output
Twinkle, twinkle, little star (with repeated notes omitted).
Note
Notice that the slide positions can be given in any order.
The best option is to play the notes in positions
Note that other solutions exist which yield a distance of
Comments