Deepak and his journey

Please share your code for this problem.

Reference Code

hey, i have some doubt.

The test case given is:-
1
2
5 1
1 2

My doubt is:-
In the given test case, c[0]=5 and c[1]=1 & l[0]=1 and l[2]=2
Now, if we go according to what the problem statement says, then Deepak wants to go from 0 to N-1 checkpoints. i.e. in given test case two checkpoints are given and Deepak wants to go from 0th to 1th checkpoint, right?
So, won’t he need to fill petrol in his car only once, i.e at 0th checkpoint because after doing so, he will reach last checkpoint, and his journey ends. So why would he fill fuel at last checkpoint? And according to this logic, cost must be 5 only.

Please tell how the answer is 7?

NO actually he also have to cross n-1 th checkpoint
for that min 2 litre petrol required and hence has to pay 2 more
so ans is 7

i know this point is not clearly mention in ques
but this you have to consider

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.