Why there is run tiime error

#include
#include
using namespace std;
int main() {
int t;
cin>>t;
for(int i=0;i<t;i++)
{
long int n;
cin>>n;
long int arr[100];
for(int j=0;j<n;j++)
{
cin>>arr[j];
}
long int cm=0;
long int ms=0;
for(int k=0;k<n;k++)
{
cm=cm+arr[k];
if(cm<0)
{
cm=0;
}

        ms=max(ms,cm);

    } 
    cout<<ms<<endl;


}

}

Hi Bhavit
You have defined size of array arr as 100 but n can be larger than 100 causing memory runtime error. Declare array of size n.

Hope it helps :slight_smile:

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.