Too slow to compute the answer to one or more testcases, how can this problem can be solved more efficient way?

Hello @rajharsh865 in this question you will need two extra arrays in which you will store the maximum element till any point and the in the second array smalles till the point.
then you intitalise your any variable with the sum of the 0th elements and subtract from it and then you will see in both the arrays if the same operation will give you any answer greater then this, that will be the answer.
Here for your reference i am attaching the code:
https://ide.codingblocks.com/s/389356
if you have any doubt you can ask here:
Happy Learning!!

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.