Https://hack.codingblocks.com/contests/c/509/197

https://hack.codingblocks.com/contests/c/509/197
my solution is:https://ide.codingblocks.com/#/s/27532
problem is that in hacker blocks output is correct but not passed in all the cases

https://ide.codingblocks.com/#/s/27578

As question says, values may be negative. So initialising d = 0 was a problem. I have made the required change
Cases like
5
-1 -2 -4 -7 -8
Expected: -1
Your code: 0