Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.7
- # -*- coding: utf-8 -*import
- from _collections import deque
- cups = deque([int(x) for x in input().split()])
- bottles = deque([int(x) for x in input().split()])
- no_more_cups = False
- no_more_bottles = False
- wasted = 0
- def overfill(c: int, b: int, cs: deque, bs: deque, w: int):
- w += b - c
- c -= b
- bs.pop()
- cs.popleft()
- return w, cs, bs, c, b
- while True:
- if not cups:
- no_more_cups = True
- break
- if not bottles:
- no_more_bottles = True
- break
- bottle = bottles[-1]
- cup = cups[0]
- if bottle >= cup:
- wasted, cups, bottles, cup, bottle = overfill(cup, bottle, cups, bottles, wasted)
- if bottle < cup:
- while True:
- if cup <= 0:
- break
- if bottle >= cup:
- wasted, cups, bottles, cup, bottle = overfill(cup, bottle, cups, bottles, wasted)
- else:
- cup -= bottle
- bottles.pop()
- bottle = bottles[-1]
- if no_more_cups:
- bottles = [str(x) for x in bottles]
- print(f'Bottles: {" ".join([bottles[i] for i in range(len(bottles) - 1, -1, -1)])}')
- print(f'Wasted litters of water: {wasted}')
- elif no_more_bottles:
- cups = [str(x) for x in cups]
- print(f'Cups: {" ".join(cups)}')
- print(f'Wasted litters of water: {wasted}')
Advertisement
Add Comment
Please, Sign In to add comment