Advertisement
Kamend1

01 Christmas Elves - Kamen Dimitrov

Feb 6th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. from collections import deque
  2.  
  3. elf_energy = deque(int(x) for x in input().split())
  4. num_materials = [int(x) for x in input().split()]
  5. total_elf_energy = 0
  6. number_toys_made = 0
  7. turns = 0
  8.  
  9. while elf_energy and num_materials:
  10.     while True:
  11.         current_elf = elf_energy.popleft()
  12.         if current_elf < 5:
  13.             current_elf = None
  14.             if not elf_energy:
  15.                 break
  16.         else:
  17.             break
  18.  
  19.     if not current_elf:
  20.         break
  21.  
  22.     current_material = num_materials.pop()
  23.     turns += 1
  24.  
  25.     if turns % 3 == 0:
  26.         current_material = int(current_material * 2)
  27.  
  28.         if current_elf >= current_material:
  29.             number_toys_made += 2
  30.             current_elf = current_elf - current_material + 1
  31.             elf_energy.append(current_elf)
  32.             total_elf_energy += current_material
  33.  
  34.         else:
  35.             num_materials.append(int(current_material / 2))
  36.             elf_energy.append(current_elf * 2)
  37.  
  38.     elif turns % 3 != 0 and turns % 5 == 0:
  39.  
  40.         if current_elf >= current_material:
  41.             current_elf = current_elf - current_material
  42.             elf_energy.append(current_elf)
  43.             total_elf_energy += current_material
  44.  
  45.         else:
  46.             num_materials.append(current_material)
  47.             elf_energy.append(current_elf * 2)
  48.  
  49.     elif turns % 15 == 0:
  50.         current_material = int(current_material * 2)
  51.  
  52.         if current_elf >= current_material:
  53.             current_elf = current_elf - current_material
  54.             elf_energy.append(current_elf)
  55.             total_elf_energy += current_material
  56.  
  57.         else:
  58.             num_materials.append(int(current_material / 2))
  59.             elf_energy.append(current_elf * 2)
  60.  
  61.     else:
  62.  
  63.         if current_elf >= current_material:
  64.             number_toys_made += 1
  65.             current_elf = current_elf - current_material + 1
  66.             elf_energy.append(current_elf)
  67.             total_elf_energy += current_material
  68.  
  69.         else:
  70.             num_materials.append(current_material)
  71.             elf_energy.append(current_elf * 2)
  72.  
  73. print(f"Toys: {number_toys_made}")
  74. print(f"Energy: {total_elf_energy:.0f}")
  75. if elf_energy:
  76.     print(f"Elves left: {', '.join(str(x) for x in elf_energy)}")
  77. if num_materials:
  78.     print(f"Boxes left: {', '.join(str(x) for x in num_materials)}")
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement