-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF.cpp
47 lines (45 loc) · 992 Bytes
/
F.cpp
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
40
41
42
43
44
45
46
47
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005],lsum[200005],rsum[200005];
int main()
{
fastio;
long long t,n,i,l,r,x;
cin>>t;
while(t--)
{
x=0;
cin>>n;
for(i=0;i<n;i++)
cin>>ara[i];
for(i=0;i<n;i++)
{
if(i==0)
lsum[i]=ara[i];
else
lsum[i]=lsum[i-1]+ara[i];
}
for(i=n-1;i>=0;i--)
{
if(i==n-1)
rsum[i]=ara[i];
else
rsum[i]=rsum[i+1]+ara[i];
}
map<long long,long long> mp1;
map<long long,long long> mp2;
for(i=0;i<n;i++)
{
mp1[lsum[i]]=i+1;
mp2[rsum[i]]=i+1;
}
for(i=0;i<n;i++)
{
if(mp2[lsum[i]]>i+1)
x=max(x,i+1+n+1-mp2[lsum[i]]);
}
cout<<x<<"\n";
}
return 0;
}