-
Notifications
You must be signed in to change notification settings - Fork 2
/
1092.py
86 lines (69 loc) · 2.44 KB
/
1092.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# [ 백준 ] 1092번: 배
def solution() -> None:
N: int = int(input())
crains: list[list[int]] = sorted(
[
[crain, 0] for crain
in list(map(int, input().split()))
],
reverse=True
)
M: int = int(input())
boxes: list[int] = sorted(list(map(int, input().split())), reverse=True)
can_all_boxes_lifted: bool = True
for box in boxes:
is_lifted: bool = False
lift_target_indexes: list[int] = []
for i in range(N):
if crains[i][0] >= box:
if crains[i][1] == 0:
crains[i][1] += 1
is_lifted = True
break
else:
lift_target_indexes.append(i)
if not is_lifted and crains[0][0] >= box:
current: int = 10000
for target_idx in lift_target_indexes:
if crains[target_idx][1] < current:
current = crains[target_idx][1]
current_idx = target_idx
crains[current_idx][1] += 1
elif crains[0][0] < box:
can_all_boxes_lifted = False
if not can_all_boxes_lifted:
print(-1)
else:
print(max(cnt for _, cnt in crains))
if __name__ == "__main__":
from io import StringIO
from unittest.mock import patch
def test_example_case(input: list[str]) -> str:
with patch("builtins.input", side_effect=input):
with patch("sys.stdout", new_callable=StringIO) as test_stdout:
solution()
return test_stdout.getvalue()
cases: list[dict[str, list[str] | str]] = [
{
"input": ["3", "6 8 9", "5", "2 5 2 4 7"],
"output": "2\n",
},
{
"input": ["2", "19 20", "7", "14 12 16 19 16 1 5"],
"output": "4\n",
},
{
"input": ["4", "23 32 25 28", "10", "5 27 10 16 24 20 2 32 18 7"],
"output": "3\n",
},
{
"input": ["10", "11 17 5 2 20 7 5 5 20 7", "5", "18 18 15 15 17"],
"output": "2\n",
},
{
"input": ["10", "11 17 5 2 20 7 5 5 20 7", "5", "18 18 15 15 21"],
"output": "-1\n",
},
]
for case in cases:
assert case["output"] == test_example_case(input=case["input"])