Advertisement
Guest User

Untitled

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