What is the problem with my approach?


in this code,tot[i] represents total petrol needed to reach the end from the ith checkpoint and dp provides answer.

you are not considering all cases
eg for the test case
2 5 1 100
1 2 30 400
your code output is 442 (2 * 1+5 * 2+1 * 430)
but output should be
436 (2 * (1+2)+1 * 430)

I hope you got my point if you want to try another approach you can refer

In case of any doubt feel free to ask :slight_smile:
If you got your answer mark your doubt as resolved