class Solution:
def longestOnes(self, a: List[int], k: int) -> int:
d = [-1]
for i in range(len(a)):
if a[i] == 0:
d.append(i)
d.append(len(a))
if k >= len(d)-2:
return len(a)
ans = 0
for i in range(0,len(d)-k-1):
ans = max(ans, d[i+k+1]-d[i]-1)
return ans