The greedy frog

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

Input

Input consists of several cases. Every case begins with nn and jj, followed by the number of flies around each stone (nn natural numbers between 0 and 10410^4). Assume 2n10002 \le n \le 1000, and 0j<n0 \le 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