Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- liters, kilometers = deque(), deque()
- for _ in range(int(input())):
- liter, kilometer = map(int, input().split())
- liters.append(liter)
- kilometers.append(kilometer)
- liters_copy = liters.copy()
- kilometers_copy = kilometers.copy()
- gas_in_tank = 0
- index = 0
- while liters_copy:
- liter = liters_copy.popleft()
- kilometer = kilometers_copy.popleft()
- gas_in_tank += liter
- if gas_in_tank >= kilometer:
- gas_in_tank -= kilometer
- else:
- liters.append(liters.popleft()) # liters.rotate(-1)
- kilometers.append(kilometers.popleft()) # kilometers.rotate(-1)
- liters_copy = liters.copy()
- kilometers_copy = kilometers.copy()
- index += 1
- gas_in_tank = 0
- print(index)
Add Comment
Please, Sign In to add comment