Writing the same logic as that in editorial, Still giving TLE?

you are getting TLE because the input is too big and you are using slow input method please add

ios_base::sync_with_stdio(false);
cin.tie(NULL);

in front of your code
Corrected Code

Thank you so much for the assistance
Marking the doubt as resolved