Advertisement
go6odn28

01_Christmas Elves

Jun 9th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. from collections import deque
  2.  
  3. MIN_NEED_ENERGY = 5
  4.  
  5.  
  6. def santa_workshop(elfs_energy_input, materials_input):
  7.     elfs_energy = deque(int(x) for x in elfs_energy_input.split())
  8.     materials = deque(int(x) for x in materials_input.split())
  9.  
  10.     total_energy = 0
  11.     made_toys = 0
  12.     counter = 0
  13.  
  14.     while elfs_energy and materials:
  15.         curr_elf = elfs_energy.popleft()
  16.  
  17.         if curr_elf < MIN_NEED_ENERGY:
  18.             continue
  19.  
  20.         counter += 1
  21.         curr_material = materials.pop()
  22.  
  23.         if counter % 3 == 0 and counter % 5 == 0:
  24.             required_energy = curr_material * 2
  25.             toys_to_add = 0
  26.         elif counter % 3 == 0:
  27.             required_energy = curr_material * 2
  28.             toys_to_add = 2
  29.         elif counter % 5 == 0:
  30.             required_energy = curr_material
  31.             toys_to_add = 0
  32.         else:
  33.             required_energy = curr_material
  34.             toys_to_add = 1
  35.  
  36.         if curr_elf >= required_energy:
  37.             total_energy += required_energy
  38.             curr_elf -= required_energy - (1 if toys_to_add > 0 and counter % 5 != 0 else 0)
  39.             made_toys += toys_to_add
  40.         else:
  41.             curr_elf *= 2
  42.             materials.appendleft(curr_material)
  43.  
  44.         elfs_energy.append(curr_elf)
  45.  
  46.     print(f"Toys: {made_toys}")
  47.     print(f"Energy: {total_energy}")
  48.  
  49.     if elfs_energy:
  50.         print(f"Elves left: {', '.join(map(str, elfs_energy))}")
  51.     if materials:
  52.         print(f"Boxes left: {', '.join(map(str, materials))}")
  53.  
  54.  
  55. elfs_energy = input()
  56. materials = input()
  57. santa_workshop(elfs_energy, materials)
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement