What's Going Wrong

PROBLEM LINK - http://www.codechef.com/problems/CARVANS

I am unable to figure out what’s going wrong here …
PLEASE HELP !

http://www.codechef.com/viewsolution/5821073

Car at position A does not depend only on car at position A-1 but on all cars at positions less than A.
Consider the following velocities

2 8 7 6 5

Only the first car is traveling at maximum speed. All the others are constrained to travel at most at speed = 2.

you hv written this statement in ur solution
if (cars[i+1] > cars[i])
ans – ;
but
if
if (cars[i+1]<=cars[i])
then u need to change the case cause minimum speed needs to be changed…
for simplicity u can store min1=cars[0];
then
if (cars[i] > min)
ans – ;
else
min=cars[i];

Oh my bad !!! Did A Blunder …Thanks @mogers for the test cases and @mb13mb13_1995 for a beautiful explanation