Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- MIN_NEED_ENERGY = 5
- elfs_energy = deque(int(x) for x in input().split())
- materials = [int(x) for x in input().split()]
- total_energy = 0
- made_toys = 0
- counter = 0
- while elfs_energy and materials:
- curr_elf = elfs_energy.popleft()
- if curr_elf < MIN_NEED_ENERGY:
- continue
- counter += 1
- curr_material = materials.pop()
- if counter % 3 != 0 and counter % 5 != 0:
- if curr_elf >= curr_material:
- made_toys += 1
- total_energy += curr_material
- curr_elf -= curr_material - 1
- else:
- curr_elf *= 2
- materials.append(curr_material)
- elif counter % 3 == 0 and counter % 5 != 0:
- if curr_elf >= curr_material * 2:
- made_toys += 2
- total_energy += curr_material * 2
- curr_elf -= curr_material * 2 - 1
- else:
- curr_elf *= 2
- materials.append(curr_material)
- elif counter % 5 == 0 and counter % 3 != 0:
- if curr_elf >= curr_material:
- total_energy += curr_material
- curr_elf -= curr_material
- else:
- curr_elf *= 2
- materials.append(curr_material)
- elif counter % 5 == 0 and counter % 3 == 0:
- if curr_elf >= curr_material * 2:
- total_energy += curr_material * 2
- curr_elf -= curr_material * 2 - 1
- else:
- curr_elf *= 2
- materials.append(curr_material)
- elfs_energy.append(curr_elf)
- print(f"Toys: {made_toys}")
- print(f"Energy: {total_energy}")
- if elfs_energy:
- print(f"Elves left: {', '.join(map(str, elfs_energy))}")
- if materials:
- print(f"Boxes left: {', '.join(map(str, materials))}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement