-
Notifications
You must be signed in to change notification settings - Fork 1
/
IB_2P_Max_Cont_1_series.py
39 lines (37 loc) · 1.08 KB
/
IB_2P_Max_Cont_1_series.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from sys import stdin as si
class Solution:
def mx(self, b,e):
return max(self.ans, (b, e), key=lambda x: x[1] - x[0])
def maxone(self, A, B):
t = B
self.ans=(0,0)
i=j=0
while j<len(A):
#print(i,j)
if A[j]==1:
j+=1
else:
if B==0:
self.ans = self.mx(i, j - 1)
i=j=j+1
continue
if t==0:
self.ans = self.mx(i,j-1)
t+=1
while i < len(A) and A[i]!=0:
i+=1
i+=1
else:
if A[j]==0:
t-=1
j+=1
if j>=len(A): j=len(A)-1
self.ans = self.mx(i,j)
return self.ans
if __name__ == "__main__":
S = Solution()
test_cases = int(si.readline().strip())
for _ in range(test_cases):
arr = list(map(int, si.readline().strip().split()))
n = int(si.readline().strip())
print(S.maxone(arr, n))