How to overcome TLE on Energetic Node

Problem name: Energetic Node(Hard Version) .
Problem link: CodeChef: Practical coding for everyone
I am trying to solve this problem but each time I get TLE .
My solution: CodeChef: Practical coding for everyone
Would anyone like to tell me what changes should I bring in my code to overcome the TLE issue?
Thanks for your help.