Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- from math import ceil
- required_values = {tuple(range(100, 200)): 'Gemstone', tuple(range(200, 300)): 'Porcelain Sculpture',
- tuple(range(300, 400)): 'Gold',
- tuple(range(400, 500)): 'Diamond Jewellery'}
- crafted_gifts = {}
- materials_stack = [int(n) for n in input().split()]
- magic_que = deque([int(n) for n in input().split()])
- while materials_stack and magic_que:
- current_material, current_magic = materials_stack[-1], magic_que[0]
- current_result = (current_material + current_magic)
- is_crafted = False
- while True:
- if current_result < 100:
- if current_result % 2 == 0:
- current_result = (current_material * 2 + current_magic * 3)
- else:
- current_result *= 2
- if 99 < current_result < 500:
- continue
- else:
- materials_stack.pop()
- magic_que.popleft()
- break
- elif current_result > 499:
- current_result = ceil(current_result/2)
- if 99 < current_result < 500:
- continue
- else:
- materials_stack.pop()
- magic_que.popleft()
- break
- for tpl in required_values.keys():
- if current_result in tpl:
- crafted_gift = required_values[tpl]
- if crafted_gift not in crafted_gifts:
- crafted_gifts[crafted_gift] = 0
- crafted_gifts[crafted_gift] += 1
- materials_stack.pop()
- magic_que.popleft()
- is_crafted = True
- break
- if is_crafted:
- break
- if ('Gemstone' in crafted_gifts and 'Porcelain Sculpture' in crafted_gifts) or ('Gold' in crafted_gifts and
- 'Diamond Jewellery' in crafted_gifts):
- print("The wedding presents are made!")
- else:
- print("Aladdin does not have enough wedding presents.")
- if materials_stack:
- print(f"Materials left: {', '.join([str(n) for n in materials_stack])}")
- if magic_que:
- print(f"Magic left: {', '.join([str(n) for n in magic_que])}")
- for gift, count in sorted(crafted_gifts.items()):
- print(f"{gift}: {count}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement