There are n petrol stations on a circular road, numbered 0,1,2,... n-1, each filling station has an upper limit, which is kept in the list limit, that is, Limit[i] is the upper limit for refueling at the petrol filling station, while driving from the I petrol station to (i+1)%n a petrol station requires cost[ I] liter oil, cost is a list. Now there is a car with no oil at the beginning, and to go around the road from a gas station and back to the beginning. give you the integer n, the list limit and the list cost, and you decide if you can complete the task. If the task can be completed, output the starting gas station number, if there are multiple, the output number is minimal. If the task cannot be completed, output-1.
Gas=0
Res=[]
For I in range (n):
Gas=0
For j in Range (N):
gas+=limit[(i+j)%n] % start with while to do more trouble
gas-=cost[(I+J)%n]
If Gas<0:break
If gas>=0:
Res.append (i)
If Len (res) ==0:print-1 % appends all possible numbers into the list, if Len = = 0, it represents no possible result
else:p rint (Res[0])
Python Little Exercise