Deepak_And_Journey


it is giving wrong answers ,where i am wrong?

The approach you are following in your code seems incorrect, the correct approach is that you need to maintain an array suppose long long int M[100001], and then you will traverse the array elements and then check,
if(i==0)
{
M[i]=cost[i];
}
else
{
M[i]=min(M[i-1],cost[i]);
}
}
And then u will initiliase : long long int final_cost=0;
such that
final_cost=final_cost+ petrol[i]*M[i];
The final _cost will determine your final answer.