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;
}
