TLE in Help Martha(CENS20G)

Yesterday i participated in Code Ensemble (Rated for Division 2) ( there was a question Help Maratha ( CENS20G) in that question i was getting TLE in my optimize solution, In question it is mention that we have to use Fast I/O i have used that also. Then after the contest i see a solution of a person ,his logic is same as mine but then also i did’t realize why i am getting TLE. Then i ask for help with my senior then he tried many things he also get TLE then after a hour he just changed endl with \n. Then he submit again,after submitting he get AC.


The difference is that endl flushes the output buffer. Which takes time especially when you need to print a lot of lines. When you dont keep endl and use “\n” you dont flush the output for every line
but once the whole the program is done you flush all of it at once.

Always use “\n” regardless for CP. Unless the question specifies to flush output (Interactive Problems).




thank you