#include
using namespace std;
int maxmsub( int a[],int n)
{ int maxtotal=a[0];
int mintillhere=a[0];
int maxtillhere=a[0];
int mintotal=a[0];
int s=0;
for(int i=0;i<n;i++)
{
if(maxtillhere+a[i]>a[i])
{
maxtillhere+=a[i];
}
else
{
maxtillhere=a[i];
}
maxtotal=max(maxtotal,maxtillhere);
if(mintillhere+a[i]<a[i])
{
mintillhere+=a[i];
}
else
{
mintillhere=a[i];
}
mintotal=min(mintotal,mintillhere);
s+=a[i];
}
if(s==mintotal)
{
return maxtotal;
}
return max(s-mintotal,maxtotal);
}
int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[100000]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<< maxmsub(a,n);
}
}
is the logic incorrect??