from bisect import bisect_left, bisect_right from itertools import accumulate if __name__ == "__main__": n, k = map(int, input().split()) nums = list(map(int, input().split())) def check(mid: int) -> bool: """每段>=mid,是否能分成>=k段""" max_ = bisect_right(preSum, mid) # 第一段的起点 for start in range(max_): if start > n: break cur = start for _ in range(k): cur = bisect_left(preSum, preSum[cur] + mid, lo=cur) if cur > start + n: break else: return True return False preSum = [0] + list(accumulate(nums + nums)) left, right = 1, (sum(nums) // k) + 1 while left <= right: mid = (left + right) // 2 if check(mid): left = mid + 1 else: right = mid - 1 print(right)