Let's take a look at my 2 submissions for problem 681C
20333485 — TLE, don't use ostringstream
20333517 — AC, use ostringstream
Briefly, the answer of the problem is a string has 1e6 lines, each line has maximum 20 characters.
In the first submission, I stored the answer in string res, then I sum "res = res + line". Finally I printed "cout << res" and got TLE
But in the second submission, I stored the answer in sout object ( an ostringstream), sum "sout << line", and printed "cout << sout.str()" and got AC ( even 4 times faster than the first submission)
I don't understand the reason behind this. Anyone could explain it ?
Thank you in advance