WHY AM I GETTING RUN ERROR?

I would like to know when do i get a run error while submitting the code.
I submit the following code for maximum subarray sum and the code was compiled successfully:

#include
using namespace std;

int main() {
int t,a[10000];
long int n;
cin>>t;
a[-1]=0;
while(t>0)
{
cin>>n;
for(int i=0 ; i<n ; i++)
{
cin>>a[i];
a[i]+=a[i-1];

	}
//sub array

int csum=0,msum=0;
for(int i=0 ; i<n-1 ; i++)
{
if(msum<a[i])
msum=a[i];

	for(int j=i+1 ; j<n ; j++)
	{
      csum=a[j]-a[i];
	 
	 if(csum>msum)
	 {
		 msum=csum;
	 }
	}
	

}
if(msum<a[n-1])
msum=a[n-1];
    cout<<msum<<endl; 
	t--;
	
}

return 0;

}

hello @amangupta
u r getting run error because
a) u are accessing negative index.

b) ur array size is small , value of n can be upto 100000 , so ur array size should be atleast 100000
image

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.

Hey,you have taken a[-1]=0 which is wrong.You can’t access -ve index.
Runtime error genrally occurs when for some input there is some memory access which is not defined or an infinite loop.