test cases are failing please tell where I am wrong
#include
using namespace std;
int maxSubarray(int a[], int n)
{
int currentSum = 0, maxSum = a[0];
for (int i = 0; i < n; i++)
{
currentSum = currentSum + a[i];
if (a[i] < 0)
{
currentSum = 0;
}
maxSum = (max(maxSum, currentSum));
}
return maxSum;
}
int main()
{
int arraySize,test;
int a[100000];
int s[20],i=0,j=0,m;
cin>>test;
m=test;
while(test>0)
{
cin >> arraySize;
for (int i = 0; i < arraySize; i++)
{
cin >> a[i];
}
s[j]=maxSubarray(a, arraySize);
j++;
test--;
}
for(int j=0;j<m;j++)
{
cout<<s[j]<<endl;
}
// cout<<s[j]<<" "<<m;
}