My solution get partial submit

problem : https://www.codechef.com/LRNDSA04/problems/QHOUSE
solution : https://www.codechef.com/viewsolution/34515157

My solution is not fully correct. Please someone check my approach. Where I got stuck?