POSITNEG (starters89) testcase failing

,

Hello everyone! I’m having trouble solving one of the problems from starters89 (POSITNEG). I would appreciate any help in identifying where I’m going wrong. Could someone take a look and give me some feedback?
https://www.codechef.com/viewsolution/96280014

The main issue with this code is that it does not handle the case where the input values are very large, which can cause overflow. So, replacing the int with long long for storing the positive and negative indices should solve your problem. Also, the abs function needs to be replaced with llabs to get the long long difference between positive and negative indices.

Here’s the link to the above fix, if you still need help:

https://www.codechef.com/viewsolution/96280560

But, why is the overflow being caused? Refer to this post in the editorial thread itself- POSITNEG - Editorial - #3 by el_tunel

Thank you!