# 【ccJUNE14】Chef and Subarray

## 描述 Description

Chef loves research! Now he is looking for subarray of maximal length with non-zero product.

Chef has an array A with N elements: A1, A2, …, AN.

Subarray Aij of array A is elements from index i to index j: Ai, Ai+1, …, Aj.

Product of subarray Aij is product of all its elements (from ith to jth).

## 输入格式 InputFormat

First line contains sinlge integer N denoting the number of elements.
Second line contains N space-separated integers A1, A2, …, AN denoting the elements of array.

## 输出格式 OutputFormat

In a single line print single integer - the maximal length of subarray with non-zero product.

6
1 0 2 3 0 4

2

## 数据范围和注释 Hint

1 ≤ N ≤ 100000
0 ≤ Ai ≤ 10000
For the first sample subarray is: {2, 3}.

CodeChef CHEFZOT

## 代码 Code

``````#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int i,j,t,n,m,l,r,k,z,y,x,ans;
int main()
{
ans=0;
t=0;
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&x);
if (x==0)
{
ans=max(ans,i-t-1);
t=i;
}
}
ans=max(ans,n+1-t-1);
printf("%d\n",ans);
return 0;
}``````