Help me understand the question Chef and Operations

Help me understand the question Chef and Operations. although i saw some solutions but still unable to understand how to solve.

1 Like

You have to start from the first index (0th) and add (b[i]-a[i]) to a[i] (to make it equal to b[i]), (a[i] - b[i])*2 to a[i+1] and (a[i] - b[i]) *3 to a[i+2]. Meanwhile if a[i] becomes greater than b[i] at any stage , you need to stop as you cannot subtract to make it equal to b[i].

You can see my solution for clarification .

Can you please tell me the use of #define io std::ios::sync_with_stdio(false);cin.tie(NULL);
I have recently started competitive programming so I am unable to understand its use.

Ya sure . Actually std::ios::sync_with_stdio(false);cin.tie(NULL); is for fast input output. Sometimes your code may get TLE even if your solution is optimal (usually when input file is large) . You can learn more about fast input output here : .

And as far as #define io std::ios::sync_with_stdio(false);cin.tie(NULL); is concerned , I have a saved template which I use in every code I write .So it is better to use #define in template instead of writing sync_with… every time .

For detailed and clear explanation of Chef and Operations solution ,you can check the editorial - .

Thank you. Got to know something new.

1 Like