Advertisement
mbstanchev

truck turns

Jan 12th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. from collections import deque
  2. num_petrol_pumps = int(input())
  3. gas_tank = 0
  4. list_of_gas_stations = deque()
  5. station_num = 0
  6. for _ in range(num_petrol_pumps):
  7. info = [int(x) for x in input().split()]
  8. list_of_gas_stations.append(info)
  9.  
  10. while list_of_gas_stations:
  11. current_pump = list_of_gas_stations.popleft()
  12. litters = current_pump [0]
  13. distance = current_pump[1]
  14. available_fuel = gas_tank + litters
  15.  
  16. if available_fuel < distance:
  17. list_of_gas_stations.append(current_pump)
  18. station_num += 1
  19. else:
  20. litters_left = (available_fuel - distance)
  21. gas_tank = litters_left
  22.  
  23. print(station_num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement