Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def make_toy(elf, material):
- if elf >= material:
- return True
- return False
- elfs_energy = deque(int(num) for num in input().split())
- materials = [int(num) for num in input().split()]
- cookie = 1
- total_energy = 0
- total_made_toys = 0
- count = 0
- while elfs_energy and materials:
- first_elf = elfs_energy.popleft()
- if first_elf < 5:
- continue
- last_material = materials.pop()
- count += 1
- if count % 3 == 0:
- last_material *= 2
- can_make_toy = make_toy(first_elf, last_material)
- if can_make_toy:
- first_elf -= last_material
- total_energy += last_material
- if count % 5 == 0:
- # No toy/toys and no cookie
- elfs_energy.append(first_elf)
- continue
- # Toy is not broken and dwarf deserves a cookie
- if count % 3 == 0:
- # Third turn. The dwarf succeeded to make 2 toys
- total_made_toys += 2
- else:
- total_made_toys += 1
- elfs_energy.append(first_elf + cookie)
- else:
- # not enough energy to make a toy
- # Return the material in the original value:
- materials.append(last_material) if count % 3 != 0 else materials.append(last_material // 2)
- first_elf *= 2
- elfs_energy.append(first_elf)
- print(f"Toys: {total_made_toys}")
- print(f"Energy: {total_energy}")
- if elfs_energy:
- print(f"Elves left: {', '.join(str(el) for el in elfs_energy)}")
- if materials:
- print(f"Boxes left: {', '.join(str(el) for el in materials)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement