In a pond there are stones in a row. A frog must go from stone 1 to , in principle going consecutively through stones 2, 3, … The problem is that the frog is very greedy, and it will not help eating all the flies around each stone that it visits. To avoid fattening too much, the frog can make up to big forward jumps, each one over at most two stones (that is, from it can jump, at most, up to ). What is the minimum number of flies that the frog will eat?
Input consists of several cases. Every case begins with and , followed by the number of flies around each stone ( natural numbers between 0 and ). Assume , and .
For every case, print the minimum number of flies that the frog will eat.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:01:15.988Z
© Jutge.org, 2006–2026.
https://jutge.org