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: http://www.spoj.com/problems/DCEPC11I/
Here is the link to my code: http://ideone.com/LcGbrb

Did you have a re-look on what are you printing?

When i ran code for sample input, it gave me-

PP [8]=1 [3]=1 
PP [4]=2 [1]=3 
PP [5]=3 [2]=3 and much more

You dont have to print this stuff. The judge will match your output with expected output, and you will get WA if for any line/position expected output!=your output. So if you are printing all this, you are sure to get WA.

I have added that to debug my program . I am not printing that actually.

//