The greedy frog

In a pond there are n stones 1, …, n in a row. A frog must go from stone
1 to n, 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 j big forward jumps, each one over at most two
stones (that is, from i it can jump, at most, up to i + 3). What is the
minimum number of flies that the frog will eat?

Input

Input consists of several cases. Every case begins with n and j,
followed by the number of flies around each stone (n natural numbers
between 0 and 10⁴). Assume 2 ≤ n ≤ 1000, and 0 ≤ j < n.

Output

For every case, print the minimum number of flies that the frog will
eat.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:01:15.988Z

© Jutge.org, 2006–2026.
https://jutge.org
