Skip to content

Commit b8113ad

Browse files
committed
84차 2번 문제 다시 풀이
1 parent 1be05bb commit b8113ad

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

live8/test84/문제2/박희경.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
"""
2-
sum(k // result) == n
3-
이때 최대 result 구하기
4-
"""
5-
61
import sys
72

83
input = sys.stdin.readline
94

105

11-
def binary_search(arr):
12-
start, end = 1, max(arr)
6+
def binary_search(cables):
7+
start, end = 1, max(cables)
138
while start <= end:
149
mid = (start + end) // 2 # 반으로 자른 길이
1510
cnt = 0
16-
for i in cm:
17-
cnt += i // mid
18-
if cnt > n: # 길이를 늘릴 필요가 있음
19-
start = mid + 1
20-
else:
11+
for cable in cables:
12+
cnt += cable // mid
13+
if cnt < n: # 길이를 줄일 필요가 있음
2114
end = mid - 1
15+
else:
16+
start = mid + 1 # 놓친 부분) 최대를 구해야 하니까..!
2217
return end
2318

2419

@@ -27,7 +22,6 @@ def binary_search(arr):
2722
for _ in range(k):
2823
cm.append(int(input()))
2924

30-
cm.sort() # [457, 539, 743, 802]
3125
print(binary_search(cm))
3226

3327

0 commit comments

Comments
 (0)