Getting unnecessary TLE on CSES - Flight Discount

CSES - Flight Discount

submission link : https://cses.fi/paste/d3163d2fd66eef927199ad/

The official solution Solution - Flight Discount (CSES) and my solution has same time complexity but still I am getting TLE. Can anyone tell me what part is taking more time?
I have tried every possible way to modify my code to make the code similar to the the AC solution but can not figure out the reason for TLE.