Advertisement
Guest User

Untitled

a guest
May 7th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. number_of_enters = int(input())
  2. list_of_petrol = []
  3. list_of_miles = []
  4. our_petrol = 0
  5. trip_done = False
  6. currIndex = 0           #keep current index
  7.  
  8. for num in range(number_of_enters):
  9.     our_enters = input().split(" ")
  10.     amount_of_petrol = int(our_enters[0])
  11.     amount_of_miles = int(our_enters[1])
  12.     list_of_petrol.append(amount_of_petrol)
  13.     list_of_miles.append(amount_of_miles)
  14. while True:
  15.     for sub_index in range(0, len(list_of_petrol)):
  16.         petrol = list_of_petrol[sub_index]
  17.         miles = list_of_miles[sub_index]
  18.         our_petrol += petrol
  19.         our_petrol -= miles
  20.         if sub_index == len(list_of_petrol) - 1:
  21.             if our_petrol >= 0:
  22.                 trip_done = True
  23.                 break
  24.         if our_petrol < 0:
  25.             our_petrol = 0
  26.             list_of_petrol.append(list_of_petrol.pop(0))        #delete first element and add it at the end
  27.             list_of_miles.append(list_of_miles.pop(0))          #delete first element and add it at the end
  28.             break
  29.  
  30.     if trip_done:
  31.         break
  32.     currIndex = currIndex + 1           #increase the current index
  33.  
  34. print(currIndex)            #print the index
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement