RE (SIGFPE) Error coming

One of my friend is getting RE (SIGFPE) error on his code. There is no division by 0 and overflow situation as per my side. Can anyone tell me why is error coming.
Code Link :
https://www.codechef.com/viewsolution/38934977

Input:
2
5 5
5 5 3 3 0
5 5
6 6 5 0 0

Expected outout:
3
4

But your code throws SIGFPE

Why? because when we found our answer in the 1st test case we break the LOOP(line number 23 in your code),So, the 1st test case’s queries are 5, 5, 3 . And remaining queries will be considered as a next test case’s input means for the 2nd test case n=3 and k=0 , so we are dividing with 0. That’s why error is coming.

You can refer my code also: https://www.codechef.com/viewsolution/38903682

Hope this helps!!!

2 Likes

Thanks for help