SPREAD2 sigsegv error

easy
easy-medium
prefix-sum
snackdown
snckql19
spread2

#1

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.


#2

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:


#3

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.


#4

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


#5

Thank You @ayush_0101 .