Please help with this LEBAMBOO code..

Hii,
Please help me correct this LEBAMBOO code…gave WAs for a close test case (I guess)…I tried to read the editorial,but found that it was not matching my algorithm I followed during my solving…I will be very grateful to the person who could point out mistake in my code or provide any general advice in improving speed.(new to programming)…thanks
Solution: http://www.codechef.com/viewsolution/2822738