I am getting run time error

@itismohiton here N ranges 1 <= N <= 100000 , so the size of array should be 100000 , not 1000.
if this resolves your doubt mark it as resolved.

@itismohiton you code will fail when all numbers are zero. Initialize ma to INT_MIN.
and put below line above if condition .
ma=max(cs,ma) ;

Doubt is resolved. It was the problem with N constraints. And there is no need of replacing this line:
ma=max(cs,ma)

but if all numbers are zero than maximum sum will be zero. Right?
and i intialized ma to to minimum number, which will be a negative number i think.
using this line ma=max(cs,ma); ma will be zero. Then where is the problem?

@Abhinav2604 if all the numbers are zero then answer will be zero obviously, but if all the numbers are negative then answer will be the smallest negative number (in magnitude). That is why we need to initialize ma to INT_MIN (negative number), now if ma updation is done after if(cs<0) then is cs is negative it would have become zero, and ma will be assigned 0 now, which would be wrong.

1 Like