I have been using endl
for competitive programming until now. For 350C - Bombs, both 79359924 and 79360060 have the same time complexity of $$$O(n \log{n})$$$, but the first gets TLE while the second gets AC. The reason is that the AC solution uses \n
instead of endl
. The difference in performance is significant because this problem requires $$$6\times 10^5+1$$$ lines of output at most!
Conclusion: Use endl
only if it is a query problem.
Reason for that is, on using
endl
output gets flushed each time whereas with\n
there is no such obligation.