using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
public static void Main() {
int.TryParse(Console.ReadLine(), out int m);
List<int> matrix = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
int.TryParse(Console.ReadLine(), out int n);
// 特殊情况:整个数组都是0
if (matrix.All(x => x == 0)) {
int maxOnes = (m + 1) / 2; // 间隔放置,最多放 (len+1)/2 个1
Console.WriteLine(n <= maxOnes ? "true" : "false");
return;
}
// 找出所有连续0块,并记录其类型和长度
List<(int length, string type)> zeroBlocks = new List<(int, string)>();
int i = 0;
while (i < m) {
if (matrix[i] == 0) {
int start = i;
while (i < m && matrix[i] == 0) {
i++;
}
int len = i - start;
// 判断这个0块的类型, 有四种类型的0块
string blockType;
if (start == 0 && i == m) {
// 全0块(已在上面处理过,这里不会执行)
blockType = "full";
} else if (start == 0) {
// 左端块
blockType = "left";
} else if (i == m) {
// 右端块
blockType = "right";
} else {
// 中间块
blockType = "middle";
}
zeroBlocks.Add((len, blockType));
} else {
i++;
}
}
// 计算每个块最多能放多少个1
int totalMaxOnes = 0;
foreach (var item in zeroBlocks) {
string type = item.type;
int len = item.length;
switch (type) {
case "middle":
totalMaxOnes += Math.Max(0, len - 2); // 两端不能放
break;
case "left":
case "right":
totalMaxOnes += Math.Max(0, len - 1); // 一端不能放
break;
case "full": // 不会执行,因为上面已处理
totalMaxOnes += (len + 1) / 2;
break;
}
}
// 判断 n 是否不超过最大可放1数
Console.WriteLine(n <= totalMaxOnes ? "true" : "false");
}
}