Problem 665
Can Place Flowers
Problem
A flowerbed is a row of plots, where 1 means a plot already has a flower and 0 means it is empty. Flowers may not be planted in neighbouring plots, and the flowerbed given to you already follows this rule. Decide whether K new flowers can be planted without breaking the rule. Scan from left to right and plant in every empty plot whose neighbours are both empty (or outside the row); planting as early as possible never hurts.
Input
The first line contains N and K. The second line contains the N plots, each 0 or 1.
Output
Print YES if K new flowers can be planted, otherwise NO.
Constraints
1 <= N <= 20000; 0 <= K <= N; no two neighbouring plots both contain 1
Example input
5 1 1 0 0 0 1
Example output
YES
Explanation
In 1 0 0 0 1, only the middle plot has two empty neighbours, so exactly one new flower fits. With K = 1 the answer is YES; with K = 2 it would be NO.