Any suggestion as of how i can improve the Time limit in this question .
TLE in Second test case
hii
try adding
ios_base::sync_with_stdio(false);
cin.tie(NULL);
these two lines at the start of your main function.
Thanks it worked , can you please explain what these lines imply ?
in c++,you can use scanf/printf or you can use cin/cout. The I/O streams of C and c++ use same buffers by default. This is said that the i/o strams of c and c++ are synchronized.
by the line ios_base::sync_with_stdio(false); , you are disabling the synchronization between the C and C++ standard streams and std::cin becomes faster.
cin.tie(NULL);
by default,cin and cout are tied together, this means that cout is flushed before cin accepts an input.cin.tie(NULL) unties cin and cout, so cout is not required to flush before accepting input.