-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path01. Apocalypse Preparation.py
63 lines (47 loc) · 1.53 KB
/
01. Apocalypse Preparation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from collections import deque
textiles = deque(map(int, input().split()))
medicaments = deque(map(int, input().split()))
owned_items = {
"Patch": 0,
"Bandage": 0,
"MedKit": 0
}
items = {
"Patch": 30,
"Bandage": 40,
"MedKit": 100
}
while textiles and medicaments:
textile, medicament = textiles.popleft(), medicaments.pop()
textile_medicaments_sum = textile + medicament
match = False
for item in items.keys():
if textile_medicaments_sum == items[item]:
owned_items[item] += 1
match = True
break
if not match:
if textile_medicaments_sum > items["MedKit"]:
owned_items["MedKit"] += 1
if medicaments:
medicament = medicaments.pop()
medicament += textile_medicaments_sum - items["MedKit"]
medicaments.append(medicament)
else:
medicament += 10
medicaments.append(medicament)
if medicaments and not textiles:
print("Textiles are empty.")
elif textiles and not medicaments:
print("Medicaments are empty.")
else:
print("Textiles and medicaments are both empty.")
items_amount = sorted(owned_items.items(), key=lambda x: (-x[1], x[0]))
for item_amount in items_amount:
item, amount = item_amount
if amount > 0:
print(f"{item} - {amount}")
if medicaments:
print(f"Medicaments left: {', '.join([str(num) for num in list(medicaments)[::-1]])}")
if textiles:
print(f"Textiles left: {', '.join([str(num) for num in textiles])}")