Problem Code : REDCGAME Last year online round icpc

https://www.codechef.com/viewsolution/27055681
The link to my solution.
I’m getting sigsegv errror in this solution.
Can anybody help me with it? If there is some logical error,please let me know.

Bro, I think that you’ve not understood the problem, your code isn’t doing what is was supposed to do. Devise a better algorithm.