Help needed CHANDF

I’m trying to do exactly what Rachit Jain sir [Greediest Competitive Programming Problem Ever ‼️ - YouTube] has described in his tutorial,and tested with all possible test cases present in the discussion forum and got correct answers but still getting TLE.Can someone please point out what i am missing.Thanks.
Here is the link:
(CodeChef: Practical coding for everyone)