Advertisement
Nenogzar

01_aladdin's_gifts

Jun 4th, 2024
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. # https://judge.softuni.org/Contests/Practice/Index/3227#0
  2. from collections import deque
  3.  
  4. materials = list(map(int, input().split()))
  5. magic_levels = deque(map(int, input().split()))
  6.  
  7. presents = {
  8.     "Gemstone": [100, 199],
  9.     "Porcelain Sculpture": [200, 299],
  10.     "Gold": [300, 399],
  11.     "Diamond Jewellery": [400, 499],
  12. }
  13.  
  14. items = {}
  15.  
  16.  
  17. def sum_item(material, magic):
  18.     return material + magic
  19.  
  20.  
  21. def check_dict(result):
  22.     for key, value in presents.items():
  23.         start, end = value
  24.         if result in range(start, end + 1):
  25.             if key not in items:
  26.                 items[key] = 1
  27.             else:
  28.                 items[key] += 1
  29.             return True
  30.     return False
  31.  
  32.  
  33. while materials and magic_levels:
  34.     material = materials.pop()
  35.     magic = magic_levels.popleft()
  36.     result = sum_item(material, magic)
  37.  
  38.     if not check_dict(result):
  39.         if result < 100:
  40.             if result % 2 == 0:
  41.                 material *= 2
  42.                 magic *= 3
  43.                 result = sum_item(material, magic)
  44.                 check_dict(result)
  45.             else:
  46.                 result *= 2
  47.                 check_dict(result)
  48.         elif result > 499:
  49.             result //= 2
  50.             check_dict(result)
  51.  
  52.  
  53. crafted_presents = ("Gemstone" in items and "Porcelain Sculpture" in items) or (
  54.             "Gold" in items and "Diamond Jewellery" in items)
  55. if crafted_presents:
  56.     print("The wedding presents are made!")
  57. else:
  58.     print("Aladdin does not have enough wedding presents.")
  59.  
  60. if materials:
  61.     print(f"Materials left: {', '.join(map(str, materials))}")
  62. if magic_levels:
  63.     print(f"Magic left: {', '.join(map(str, magic_levels))}")
  64.  
  65. for key in sorted(items):
  66.     print(f"{key}: {items[key]}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement