Nenogzar

truck

Apr 27th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. from collections import deque
  2.  
  3. liters, kilometers = deque(), deque()
  4.  
  5. for _ in range(int(input())):
  6.     liter, kilometer = map(int, input().split())
  7.     liters.append(liter)
  8.     kilometers.append(kilometer)
  9.  
  10. liters_copy = liters.copy()
  11. kilometers_copy = kilometers.copy()
  12.  
  13. gas_in_tank = 0
  14. index = 0
  15.  
  16. while liters_copy:
  17.     liter = liters_copy.popleft()
  18.     kilometer = kilometers_copy.popleft()
  19.     gas_in_tank += liter
  20.  
  21.     if gas_in_tank >= kilometer:
  22.         gas_in_tank -= kilometer
  23.     else:
  24.         liters.append(liters.popleft()) # liters.rotate(-1)
  25.         kilometers.append(kilometers.popleft()) # kilometers.rotate(-1)
  26.         liters_copy = liters.copy()
  27.         kilometers_copy = kilometers.copy()
  28.         index += 1
  29.         gas_in_tank = 0
  30.  
  31. print(index)
Add Comment
Please, Sign In to add comment