Advertisement
Nenogzar

01. Christmas Elves

Jun 9th, 2024
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. from collections import deque
  2. elf_energy = deque(int(x) for x in input().split())
  3. materials = deque(int(x) for x in input().split())
  4. toys_counter = 0
  5. day_counter = 0
  6. total_energy = 0
  7. while elf_energy and materials:
  8.     while elf_energy[0] < 5:
  9.         elf_energy.popleft()
  10.         if len(elf_energy) == 0:
  11.             break
  12.     if len(elf_energy) == 0:
  13.         break
  14.     day_counter += 1
  15.     if day_counter % 3 != 0:
  16.         if elf_energy[0] >= materials[-1]:
  17.             if day_counter % 5 == 0:
  18.                 elf_energy[0] -= materials[-1]
  19.             else:
  20.                 elf_energy[0] -= materials[-1] - 1
  21.                 toys_counter += 1
  22.             total_energy += materials[-1]
  23.             materials.pop()
  24.             elf_energy.append(elf_energy.popleft())
  25.         else:
  26.             elf_energy[0] *= 2
  27.             elf_energy.append(elf_energy.popleft())
  28.     elif day_counter % 3 == 0:
  29.         if elf_energy[0] >= materials[-1] * 2:
  30.             if day_counter % 5 == 0:
  31.                 elf_energy[0] -= materials[-1] * 2
  32.             else:
  33.                 elf_energy[0] -= materials[-1] * 2 - 1
  34.                 toys_counter += 2
  35.             total_energy += materials[-1] * 2
  36.             materials.pop()
  37.             elf_energy.append(elf_energy.popleft())
  38.         else:
  39.             elf_energy[0] *= 2
  40.             elf_energy.append(elf_energy.popleft())
  41. print(f"Toys: {toys_counter}")
  42. print(f"Energy: {total_energy}")
  43. if len(elf_energy) > 0:
  44.     print(f"Elves left: {', '.join(str(x) for x in elf_energy)}")
  45. if len(materials) > 0:
  46.     print(f"Boxes left: {', '.join(str(x) for x in materials)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement