Help me with the code , for some cases it works ,with some it doesnt

5
-5 -2 5 7 -1
with this input it works.

with this input it says there was problem in running the code.
5
5 -2 5 7 -1

help me with this.

sometimes it works ,sometimes keeps saying there is problem in running the code.why is that?

@Kriti_Anand
With the second input it is compiling perfectly. I am unable to find an issue.

@Kriti_Anand
The only issue is with the time complexity. It is O(n*n) as of now. Try reducing it to O(n) using Kadanes Algo.