Created
March 6, 2013 21:22
-
-
Save rohit-nsit08/5103208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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