Advertisement
Nenogzar

5. Truck Tour

May 14th, 2024
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 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())  # or lite
  7.     # liter, kilometer = deque([int(x) for x in input().split()] for _ in range(int(input())))
  8.     liters.append(liter)
  9.     kilometers.append(kilometer)
  10.  
  11. liters_copy = liters.copy()
  12. kilometers_copy = kilometers.copy()
  13.  
  14. tank_capacity = 0
  15. count_run = 0
  16.  
  17. while liters_copy:
  18.     liter = liters_copy.popleft()
  19.     kilometer = kilometers_copy.popleft()
  20.     tank_capacity += liter
  21.  
  22.     if tank_capacity >= kilometer:
  23.         tank_capacity -= kilometer
  24.     else:
  25.         liters.append(liters.popleft())  # liters.rotate(-1)
  26.         kilometers.append(kilometers.popleft())  # kilometers.rotate(-1)
  27.         liters_copy = liters.copy()
  28.         kilometers_copy = kilometers.copy()
  29.         count_run += 1
  30.         tank_capacity = 0
  31.  
  32. print(count_run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement