Maximum sub array sum

#include
using namespace std;

int main()
{
int t;
cin>>t;
int n;
cin>>n;
int a[10000];
int maxsum=0;
while(t!=0)
{

for(int i=0;i<n;i++)
{
	cin>>a[i];
}
int sum=0;
for(int i=0;i<n;i++)
{
	sum=sum+a[i];
	sum=sum<0?0:sum;
	maxsum=max(sum,maxsum);
}
cout<<maxsum<<endl;
t--;
}

}
the code is showing run time error please help

Hi @AKSHET , you have to take the size of array inside the while loop also initialize maxsum=0 for every test case and since the size of array can be 100000 and u have declared array size to be 10000
which will result in runtime error

Here, i have corrected your code

in case of any doubt feel free to ask :slight_smile:
If you got the answer then mark your doubt as resolved

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.