Why my code has failed testcases

here is my code

int main() {
int n,N,a[1000];

cin>>n;
while(n>0){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	int cs=0;
	int ms=0;
	for(int i=0;i<N;i++){
		cs=cs+a[i];
		if(cs<0)
		cs=0;
		ms = max(cs,ms);
	}
	cout<<ms<<endl;
n--;
}
return 0;

}
Its compilation is correct ,but i can’t submit it please help.

you need to reintialize ms in each iteration.

you are not considering the case when all the array elements being negative…
in that case you have to print the maximum of all the negative numbers
For example
5
-1 -2 -3 -4 -5
your out put should be -1

I changed my code but still I can’t submit it because of run error. https://ide.codingblocks.com/s/294625

this is O(n^2) algorithm you need to use O(n) please study about kadane’s algo for that.

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.