Minimum money needed problem


The code is giving incorrect output

That’s beacuase of if condition in for loop and also initialization is long long int which will fail your test case for eg for input:
5 10
-1 33 -1 176 -1 46 -1 120 -1 300
Expected output is:
112
Yours is giving: 165
Take reference from this code


It’s similar to yours just few changes of declaration, apply it in your code and your answer will get accepted.

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.