Doubt in POSTIT question

Please ,Help me find the bug in my code of the question POSTIT.I am not able to identify what is going wrong with my code in some cases.So Please help.Below is the link to my code https://www.codechef.com/viewsolution/10258958

You can start by making your code readable and explaining your algorithm so that we can help.

Hey,I have updated the solution .Please have a look