I found an interesting problem on https://codeforces.com/problemset/problem/1066/B:
Vova's house is an array consisting of $n$ elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The $i$-th element of the array is $1$ if there is a heater in the position $i$, otherwise the $i$-th element of the array is $0$.

Each heater has a value $r$ ($r$ is the same for all heaters). This value means that the heater at the position $pos$ can warm up all the elements in range $[pos - r + 1; pos + r - 1]$.

Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater. 

Vova's target is to warm up the whole house (all the elements of the array), i.e. if $n = 6$, $r = 2$ and heaters are at positions $2$ and $5$, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first $3$ elements will be warmed up by the first heater and the last $3$ elements will be warmed up by the second heater).

Initially, all the heaters are off.

But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.

Your task is to find this number of heaters or say that it is impossible to warm up the whole house.


-----Input-----

The first line of the input contains two integers $n$ and $r$ ($1 \le n, r \le 1000$) — the number of elements in the array and the value of heaters.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 1$) — the Vova's house description.


-----Output-----

Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.


-----Examples-----
Input
6 2
0 1 1 0 0 1

Output
3

Input
5 3
1 0 0 0 1

Output
2

Input
5 10
0 0 0 0 0

Output
-1

Input
10 3
0 0 1 1 0 1 0 0 0...

I tried it in Python, but could not do it. Can you solve it?
def main():
    n, r = list(map(int, input().split()))
    arr = [True if c == '1' else False for c in input().split()]
    #print(arr)

    last_heated = 0
    tot = 0
    last_turned = -1
    while last_heated < n:
        optim = last_heated + r - 1

        while True:
            if optim < 0:
                print('-1')
                return
            if optim <= last_turned:
                print('-1')
                return
            if optim >= n:
                optim -= 1
                continue
            if arr[optim]:
                # found a heater
                tot += 1
                last_heated = optim + r
                last_turned = optim
                #print('turn on ' + str(optim))
                break
            optim -= 1
    print(tot)


def __starting_point():
    main()

__starting_point()