Advertisement
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()) # or lite
- # liter, kilometer = deque([int(x) for x in input().split()] for _ in range(int(input())))
- liters.append(liter)
- kilometers.append(kilometer)
- liters_copy = liters.copy()
- kilometers_copy = kilometers.copy()
- tank_capacity = 0
- count_run = 0
- while liters_copy:
- liter = liters_copy.popleft()
- kilometer = kilometers_copy.popleft()
- tank_capacity += liter
- if tank_capacity >= kilometer:
- tank_capacity -= kilometer
- else:
- liters.append(liters.popleft()) # liters.rotate(-1)
- kilometers.append(kilometers.popleft()) # kilometers.rotate(-1)
- liters_copy = liters.copy()
- kilometers_copy = kilometers.copy()
- count_run += 1
- tank_capacity = 0
- print(count_run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement