-
Notifications
You must be signed in to change notification settings - Fork 2
/
1654.py
52 lines (38 loc) · 1.33 KB
/
1654.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
# [ 백준 ] 1654번: 랜선 자르기
def solution() -> None:
import sys
input = sys.stdin.readline
K, N = map(int, input().split())
lans: list[int] = [ int(input()) for _ in range(K) ]
answer: int = 0
start, end = 1, (max(lans) // (N // K)) + 1
while start <= end:
middle: int = (start + end) // 2
target: int = sum([lan // middle for lan in lans])
if target >= N:
if answer < middle:
answer = middle
start = middle + 1
else:
end = middle - 1
print(answer)
if __name__ == "__main__":
from io import StringIO
from unittest.mock import patch
def test_example_case(input: list[str]) -> str:
with patch("sys.stdin.readline", 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": ["4 11", "802", "743", "457", "539"],
"output": "200\n"
},
{
"input": ["4 4", "400", "400", "400", "400"],
"output": "400\n"
}
]
for case in cases:
assert case["output"] == test_example_case(input=case["input"])