import sys
input = sys.stdin.readline
N, K = map(int, input().split())
len_array = []
for i in range(N):
len_line = int(input())
len_array.append(len_line)
start_line_length = max(len_array)
while start_line_length:
left_number = 0
for i in len_array:
while i >= start_line_length:
i -= start_line_length
left_number += 1
if left_number >= K:
print(start_line_length)
break
start_line_length -= 1
print(start_line_length)
시간복잡도 O(N^2)로 문제를 해결했지만 시간초과로 인해 O(N log M)으로 다시 코드를 작성하였고
이분탐색을 이용하여 문제를 해결했습니다
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
len_array = []
for i in range(N):
len_line = int(input())
len_array.append(len_line)
start_line_length = max(len_array)
while start_line_length:
total2 = 0
for i in len_array:
while i >= start_line_length:
i -= start_line_length
total2 += 1
if total2 >= K:
print(start_line_length)
break
start_line_length -= 1