Please help with Snake Eating.(3 days spent ,no solution)

I have been trying the Snake Eating question for 3 days now.I’m still getting a TLE.Please help. I want to solve this question really bad.My latest solution getting TLE

Probably ur second binary search fn was wrong, I updated it slightly to get AC

your solution:

Sorry i used lower_bound,u could try it with ur fn too.