Why i am getting wrong answer in CookOff CakeWalk

can someone tell me what’s wrong in my code

I also did this question with recursion, what i’ve come to know that its actually a TLE. The same code gave wrong answer during the competition but when competition ended I just added a new blank line and submitted again, it gave TLE. Well if you consider the edge case TLE is obvious.