Max Subarray sum

My code is giving the correct output but it isn’t passing any test case . The ‘Run error’ is being displayed at all test cases .

Hey @Maazkhan
Updated your code and menrtioned the changes in comments

#include<iostream>
#include<algorithm>
using namespace std;

int main() {
    int t;
	cin>>t;
	int j=0; //initialize here
	while(j<t) {
	    int n;
		cin>>n;
		long  int a[100000];//Increase size acc to question
		for ( int i=0 ; i<n ; i++) {
			cin>>a[i];
		}
		 int csum=0;
		 int msum=0;
		for (int i=0 ; i<n ; i++) {
			csum=csum+a[i];
			if (csum<0){
				csum=0;
			}
			msum=max(csum,msum);
		}
		j++;
		cout<<msum<<endl;
	}
	return 0;

}

If this resolves your query then please mark it as resolved :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.