Deepak and his journey


The code is giving incorrect output

@jha.aparna17 you are only updating your answer when if condition is getting satisfied

 if(cost[i]<min_cost)
            {
                ans+=cost[i]*petrol[i];
                min_cost=cost[i];
            }

but you should calculate answer for every iteration like this:

if(cost[i]<min_cost)
{
min_cost=cost[i];
}
ans+=min_cost*petrol[i];

and use long long int in place of int in your code.

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.