Advertisement
Nenogzar

Untitled

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