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

https://www.codechef.com/viewsolution/32078879

I’m getting TLE for a single test case in the second sub-task, any idea on how to further optimise the code?