-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP3213.py
59 lines (43 loc) · 1.29 KB
/
P3213.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
def select_min(p1, p2):
return p1 if p1 < p2 else p2
if __name__ == '__main__':
pizza = {
"1/4": 0,
"1/2": 0,
"3/4": 0,
"full": 0
}
for _ in range(int(input())):
pizza_type = input().strip()
pizza[pizza_type] += 1
# 1/4 + 3/4
if pizza["1/4"] and pizza["3/4"]:
min_cnt = select_min(pizza["1/4"], pizza["3/4"])
pizza["1/4"] -= min_cnt
pizza["3/4"] -= min_cnt
pizza["full"] += min_cnt
# 1/2 * 2
if pizza["1/2"] // 2:
min_cnt = pizza["1/2"] // 2
pizza["1/2"] -= min_cnt * 2
pizza["full"] += min_cnt
# 1/2 + 1/4 * 2
if pizza["1/2"] and pizza["1/4"] // 2:
min_cnt = select_min(pizza["1/2"], pizza["1/4"] // 2)
pizza["1/2"] -= min_cnt * 1
pizza["1/4"] -= min_cnt * 2
pizza["full"] += min_cnt
# 1/4 * 4
if pizza["1/4"] // 4:
min_cnt = pizza["1/4"] // 4
pizza["1/4"] -= min_cnt * 4
pizza["full"] += min_cnt
# 남은 조각 모으기
if pizza["1/2"] and pizza["1/4"]:
pizza["1/2"] -= 1
pizza["1/4"] -= 1
pizza["full"] += 1
if pizza["1/4"] > 1:
pizza["1/4"] = 0
pizza["full"] += 1
print(pizza["1/2"] + pizza["1/4"] + pizza["3/4"] + pizza["full"])