Need a better Solution for this Problem

my code is giving a time-limit error for one test case, Im not able to think of any other solution.

Hey @sagard0011
Just add this in your main method before taking input.
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

If your doubt is resolved please mark it as closed.

What is this statement for?


A great in depth explanation is given her.

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.