COCI '16 Contest 6 #2 Telefoni

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

There are N desks in a room, placed from left to right, one next to each other. Some desks have phones on them, whereas some desks are empty. All phones are broken, so the phone on the ith desk will ring if the phone at jth desk rings, which is at most D desks away from the ith desk. In other words, it holds |ji|D. The first and the last desk will always have a phone on them. In the beginning the leftmost phone rings. What is the minimal amount of new phones to be placed on the desks so that the last phone rings?

Input Specification

The first line of input contains two positive integers, N (1N300000) and D (1DN).

The following line contains N numbers 0 or 1. If the ith number is 1, then the ith desk from the left has a phone on it, otherwise the ith desk is empty.

Output Specification

The first and only line of output must contain the required minimal number of phones.

Scoring

In test cases worth 40 points in total, it will hold 1N20.

Sample Input 1

Copy
4 1
1 0 1 1

Sample Output 1

Copy
1

Sample Input 2

Copy
5 2
1 0 0 0 1

Sample Output 2

Copy
1

Sample Input 3

Copy
8 2
1 1 0 0 1 0 0 1

Sample Output 3

Copy
2

Comments

There are no comments at the moment.