RUN ERROR IN MAX SUB ARRAY SUM

Why I’m getting run error in the below code?

code:

#include
using namespace std;
int main() {
int t,n;
cin>>t;
int a[1000];
int cursum=0;
int maxsum=0;
for(int i=0;i<t;i++){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cursum=cursum+a[i];
if(cursum<0){
cursum=0;
}
if(maxsum<cursum){
maxsum=cursum;
}
}
cout<<maxsum<<endl;
}
return 0;
}

Check the constraints
Constraints

1 <= N <= 100000

But you have restricted your array size to 1000.

Save your code on ide.codingblocks.com and then share its link. I will make the corrections in it.

Check now

1 Like