Print,Scanf taking more time compared to cin and cout

In following problem of july19 cook-off - .
I made two submissions , the first one is (using cin,cout)
and the second one is (using scanf,print)

I tested few more times and i saw that first code was taking less time (0.96 secs) whereas the second one taking 1.02 secs .

I know the difference is very less , but if time-limit was 1 sec then it might have created problem.
What is the reason behind it ? I mean printf,scanf should work faster then cin,cout.

By default, cin / cout waste time synchronizing themselves with the C library’s stdio buffers, so that you can freely intermix calls to scanf / printf with operations on cin / cout . Turn this off with (std::ios_base::sync_with_stdio(false);) .

Source - Here

1 Like