Https://www.codechef.com/viewsolution/38134888

my code:CodeChef: Practical coding for everyone
question:CodeChef: Practical coding for everyone

tried whole day for the question ,not getting right answer ,
guys plz help,
i guess the approach is right,but i m not getting where im going wrong?

plz help