#P7786. [COCI 2016/2017 #6] Telefoni
[COCI 2016/2017 #6] Telefoni
Description
There are desks in an office arranged from left to right, and some desks have telephones.
After the telephone on desk rings, the telephone on desk will also ring if and only if .
You are given the current placement of telephones. Find the minimum number of telephones that need to be added so that the telephone on the last desk will ring.
It is guaranteed that there is a telephone on the first desk and on the last desk.
Input Format
The first line contains two positive integers and , representing the number of desks and the maximum distance.
The second line contains integers . If , it means there is a telephone on this desk; if , it means there is no telephone.
Output Format
One line with one integer, the minimum number of telephones that need to be added.
4 1
1 0 1 1
1
5 2
1 0 0 0 1
1
8 2
1 1 0 0 1 0 0 1
2
Hint
Sample Explanation #1
Add a telephone on desk , and then the telephone on desk can ring.
Sample Explanation #2
Add a telephone on desk , and then the telephone on desk can ring.
Sample Explanation #3
Add one telephone each on desks and , and then the telephone on desk can ring.
Constraints
For of the testdata, .
For of the testdata, .
Notes
The score of this problem follows the original COCI setting, with a full score of .
Translated from COCI2016_2017 CONTEST #6 T2 TELEFONI.
Translated by ChatGPT 5
京公网安备 11011102002149号