WA in impossible boss on spoj.

I am trying to solve the problem impossible boss on spoj. Its giving wrong answer for certain cases. I think there is some problem in my lazy propogation . Can someone please tell the problem in my code. The link to the question is: SPOJ.com - Problem DCEPC11I Here is the link to my code: LcGbrb - Online C++ Compiler & Debugging Tool - Ideone.com