CHEFAOR - Editorial

I used dnc only and it passed
https://www.codechef.com/viewsolution/31011842

Can anyone help in debugging the code? TLE !!
https://www.codechef.com/viewsolution/90228825

Here I find another solution with a similar code but pass-
https://www.codechef.com/viewsolution/86862907