n,m = map(int,input().split()) #강의수 #M개의 블루레이 .
time = list(map(int,input().split()))
# 블루레이크기를 이분탐색하자 !
start,end = max(time),sum(time)
result = end
while start<=end:
mid = (start+end)//2
total =0 ; cnt = 0
for times in time:
if total+times > mid:
cnt+=1
total=0
total += times
if total: # 토탈이 남아있다면
cnt+=1 #1개추가
# print(f"start : {start} mid : {mid} end : {end}, cnt {cnt}")
if cnt<=m: #총 개수가 블루레이보다 작거나 같다
result = min(result,mid)
end = mid - 1
else :
start = mid + 1
print(result)
블루레이의 크기를 이분탐색을 진행하는 문제이다.
블루레이의 최소크기를 영상 하나의 최대길이로 잡고
블루레이의 최대크기를 영상 총합으로 잡아서 start,end를 만들어주면된다.
그 후 이진 탐색을 진행하면서 총 개수가 원하는 개수보다 작으면 블루레이 크기를 줄여줘야하기 때면우 end=mid -1로 잡고
그렇지 않다면 start=mid+1로 이진탐색을 진행하면 된다.