SPREAD2 sigsegv error

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

why was this solution showing a sigsegv error when I used a prefix sum array to solve the problem?
Any help would be appreciated. Thanks in advance.

1 Like

The only reason i can see is int overflow just make array presum i.e. a and variable i long long. The overflow is causing your variable i to go less than 0 which will make -ve array indexing and hence RE.I guess you will get the idea :slight_smile:

Yes, the problem occurs at line 21 in your code. If the input is large and value of ‘i’ gets above INT_MAX, ‘ioverflows for next iteration and the indexing gets disturbed ! Hence SIGSEGV.

Thanks @ram_24 . A silly mistake costed me 19 penalty attempts.

1 Like

Thank You @ayush_0101 .