题目
题解
pos[i]为到第i个数为止乘积为正数的最长长度;
neg[i]为到第i个数为止乘积为负数的最长长度;
n = int(input())
a = list(map(int,input().split()))
pos = [0]*n
neg = [0]*n
if a[0] > 0:
pos[0] = 1
elif a[0] < 0:
neg[0] = 1
res = pos[0]
for i in range(1,n):
if a[i] > 0:
pos[i] = pos[i-1] + 1
neg[i] = neg[i-1] + 1 if neg[i-1] > 0 else 0
elif a[i] < 0:
pos[i] = neg[i-1] + 1 if neg[i-1] > 0 else 0
neg[i] = pos[i-1] + 1
else:
pos[i] = 0
neg[i] = 0
print(max(pos))