Maximum subarray sum

it is showing a run error when I am submitting the code. pls help
here is the code :-

#include
using namespace std;
int main() {
int t,n,a[1000];
int i,j,k;
int sum=0,max;
cin>>t;
while(t–)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}

for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
for(k=j;k<=i;k++)
{
sum=sum+a[k];
}
if(i==0)
{
max=sum;
}
if(sum>max)
{
max=sum;
}
sum=0;
}

}
cout<<max<<endl;
}

return 0;

}

@Keshav99 See the contraints:
Constraints
1 <= N <= 100000

1 <= t <= 20

-100000000 <= A[i] <= 100000000

It is large enough but you have restricted your array a to a size 1000. This is causing run error. Also since the constraints are large enough, this naive approach to find the maximum subarray sum will not work. Please follow the Kadane’s algorithm which is already taught in the lecture videos.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.