Why i am getting TLE?

https://www.codechef.com/OCT18B/problems/HMAPPY
my 2 solutions
https://ide.codingblocks.com/#/s/31352
https://ide.codingblocks.com/#/s/31353
any hints please?

You shouldn’t expect hints of live contest. In order to gain the most from it, try them first yourself and we can discuss after the contest ends

Any testcase for which my code is failing?

Believe me, it’ll be great if YOU come up with the bug