what is the problem with my code it’s giving wrong answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int t;
cin>>t;
while(t–)
{
long long int n,i,j,f=0,g=0;
cin>>n;
long long int a[n]={0};
long long int s[n+1]={0};
for(i=0;i<n;i++)
{
cin>>a[i];
s[i+1]=s[i]+a[i];
if(a[i]<0)
{
f=1;
}
else
{
g=1;
}
}
if(g==1&&f==0)
{
cout<<s[n]<<endl;
}
else if(f==1&&g==0)
{
cout<<*max_element(a,a+n)<<endl;
}
else
{
long long int ans=s[n];
i=0;
j=n-1;
while(i<=j)
{
while(a[i]<0)
{
i++;
}
while(a[j]<0)
{
j–;
}
if(i<=j)
{
if(s[j+1]-s[i]>ans)
{
ans=s[j+1]-s[i];
}
}
if(a[i]>a[j])
{
j–;
}
else
{
i++;
}
}
cout<<ans<<endl;
}
}
return 0;
}