Advertisement
MNNM2021

Untitled

Feb 11th, 2024
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from collections import deque
  2.  
  3. elfs = deque([int(x) for x in input().split()])  # [10 16 13 25]
  4. materials = deque(int(x) for x in input().split())  # [12 11 8]
  5.  
  6. total_energy = 0
  7. total_toys = 0
  8. number_of_tries = 0  # number_of_tries
  9.  
  10. while elfs and materials:
  11.     elf = elfs.popleft()
  12.     material = materials[-1]
  13.  
  14.     if elf < 5:
  15.         continue
  16.  
  17.     number_of_tries += 1
  18.     current_toys_count = 0
  19.  
  20.     if number_of_tries % 3 == 0:
  21.         material *= 2
  22.         current_toys_count += 1
  23.  
  24.     if elf >= material:
  25.         total_energy += material
  26.         elf -= material
  27.  
  28.         if number_of_tries % 5 != 0:
  29.             elf += 1
  30.             current_toys_count += 1
  31.         else:
  32.             current_toys_count = 0  # нулираме играчката
  33.  
  34.         materials.pop()
  35.     else:
  36.         elf *= 2
  37.         current_toys_count = 0
  38.  
  39.     total_toys += current_toys_count
  40.     elfs.append(elf)
  41.  
  42.  
  43. print(f"Toys: {total_toys}")
  44. print(f"Energy: {total_energy}")
  45.  
  46. if elfs:
  47.     print(f"Elves left: {', '.join(str(x) for x in elfs)}")
  48. if materials:
  49.     print(f"Boxes left: {', '.join(str(x) for x in materials)}")
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement