Skip to content

Instantly share code, notes, and snippets.

@rohit-nsit08
Created March 6, 2013 21:22
Show Gist options
  • Save rohit-nsit08/5103208 to your computer and use it in GitHub Desktop.
Save rohit-nsit08/5103208 to your computer and use it in GitHub Desktop.
fuel = map(lambda x:int(x), raw_input().split())
distance = map(lambda x:int(x), raw_input().split())
# takes the standard input as space separated integers in two lines.
diff = [b-a for b,a in zip(fuel, distance)] # creates the diff array
diff = diff + diff # to account for cyclic array
start = 0 # let say we start from 0 the position
end = 0
summation = 0
counter = 0 # keeps the count of petrol pumps accessed
for i in range(len(diff)):
if(end - start >= len(distance)):
break;
summation += diff[i]
end += 1
if(summation < 0):
summation = 0
start +=1
end = start
if(end - start == len(distance)): # we covered exactly 5 petrol pumps
print start
else:
print "solution doesn't exist"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment