累加数组每一项
未排序数组中累加和为给定值的最长子数组系列问题补1
http://www.nowcoder.com/questionTerminal/545544c060804eceaed0bb84fcd992fb
include <bits/stdc++.h>
using namespace std;
int main()
{
int N,t,len=0;
cin>>N;
vector<int> arr(N+1,0);
for(int i=1;i<=N;i++)
{
cin>>t;
if(t>0)
arr[i]=arr[i-1]+1;
else if(t<0)
arr[i]=arr[i-1]-1;
else
arr[i]=arr[i-1];
if(arr[i]==0)
len = max(len,i);
}</int>
for(int i=1;i<=N;i++) for(int j=N;j>len+i;j--) { if(arr[j]==arr[i]) { len =max(len,j-i); break; } } cout<<len<<endl; return 0;
}