TLE in one case

please sir check my code iam getting one TLE

Hi @pankajsingh add the lines
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Just inside your main function OR use scanf and printf (Cstyle) instead of cin and cout
for faster I/O as the input can be very large and reading large input can take lot of time so you will need a faster method like scanf ( faster than cin) for taking an input

In case of any doubt feel free to ask :slight_smile:
If you got the answer mark your doubt as resolved

ios_base::sync_with_stdio(false); cin.tie(NULL); what these line means

these lines are used to achieve same speed as scanf and printf using cin and cout

This disables the synchronization between the C and C++ standard streams. By default, all standard streams are synchronized, which in practice allows you to mix C- and C++ -style I/O and get sensible and expected results. synchronizing let both worlds to share the same buffers. For example cout << “Hello”; printf(“World”); cout << “Ciao”;; without synchronization you’ll never know if you’ll get HelloCiaoWorld or HelloWorldCiao or WorldHelloCiao…
If you disable the synchronization, then C++ streams are allowed to have their own independent buffers, which makes mixing C- and C++ -style I/O an adventure thus as a side effect you get a faster input processing

I will suggest u to read this article to get the clear understanding on fast I/O

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.