Please have a look at these two solutions, the code using cout is accepted but the code using printf is giving TLE. I always thought printf is faster than than cout. What do you think?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
Please have a look at these two solutions, the code using cout is accepted but the code using printf is giving TLE. I always thought printf is faster than than cout. What do you think?
| Name |
|---|



I don't know for sure but maybe you have TLE on the first submission because of combining cin and printf? Try to use stdio only
Firstly, your solution is really slow.
Secondly http://codeforces.me/contest/436/submission/6890816 scanf is faster than cin, but i guess printf is slower when it comes to long long int.
Anyway if you have right solution it doesn't matter if u're using cout or printf :)
EDIT: Check this ( I've changed your solution so i can use int everywhere )
http://codeforces.me/contest/436/submission/6890858
http://codeforces.me/contest/436/submission/6890844
If you write these 2 lines in the beggining of your code:
ios_base::sync_with_stdio(false);
cin.tie(0);
will make cin faster than csdtio. But its very important to use "\n" instead of endl for newline!!!
Why "\n" is recommended in this case?
because
endlprints "\n" and then flushes the streamI didn't know that. Thanks!
http://codeforces.me/contest/436/submission/6891424
I doubt it's faster, maybe i've done something wrong, but I guess I didn't. Anyway it's true that '\n' is much faster than endl.
Can you please explain what these two lines actually do,
ios_base::sync_with_stdio(false); cin.tie(0);
http://lmgtfy.com/?q=ios_base+sync+with+stdio+0
try the same with second one :) there's a lot of information in internet, so search for it and read it :)
Well yes these solutions can be made using priority queue, and time limit would come down.
See if this helps in any way.