#P7786. Minimum Added Phones for Chain Ringing

    ID: 20972 Type: Default 1000ms 256MiB

Minimum Added Phones for Chain Ringing

Minimum Added Phones for Chain Ringing

An office has N desks arranged from left to right. Some desks have phones placed on them. When the phone on the jth desk rings, the phone on the ith desk will ring if and only if \(|j-i| \le D\).

You are given the current placement of phones. Your task is to determine the minimum number of additional phones that need to be added so that the phone on the last desk eventually rings. It is guaranteed that both the first and the last desk already have a phone.

inputFormat

The first line contains two integers N and D \( (2 \le N \le 10^5, 1 \le D \le N-1) \) indicating the number of desks and the maximum distance a ringing phone can affect.

The second line contains N integers, each either 0 or 1. The \(ith\) integer is 1 if there is a phone on the \(ith\) desk and 0 otherwise. It is guaranteed that the first and the last integers are 1.

outputFormat

Print a single integer which is the minimum number of additional phones that need to be added so that the phone on the last desk rings.

sample

8 2
1 0 1 0 0 1 0 1
1

</p>