import math
import collections
n, k = map(int, input().split())
W = collections.deque()
for i in range(n):
    W.append(int(input()))
left = max(math.ceil(sum(W) / k), max(W))
right = sum(W)
center = (left + right) // 2
# print('------')
while left < right:
    i = 1
    track = 0
    # print(center)
    for w in W:
        # if center == 26:
        #     print('track: ' + str(track))
        track += w
        if track > center:
            track = w
            i += 1
            if i > k:
                left = center + 1
                break
    else:
        right = center
    center = (left + right) // 2
print(center) import math math import collections collections n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k W = collections.deque() W collections.deque() collections.deque collections deque for i in range(n):
    W.append(int(input())) i range(n) range n W.append(int(input())) W.append W append int(input()) int input() input left = max(math.ceil(sum(W) / k), max(W)) left max(math.ceil(sum(W) / k), max(W)) max math.ceil(sum(W) / k) math.ceil math ceil sum(W) / k sum(W) sum W k max(W) max W right = sum(W) right sum(W) sum W center = (left + right) // 2 center (left + right) // 2 left + right left right 2 while left < right:
    i = 1
    track = 0
    # print(center)
    for w in W:
        # if center == 26:
        #     print('track: ' + str(track))
        track += w
        if track > center:
            track = w
            i += 1
            if i > k:
                left = center + 1
                break
    else:
        right = center
    center = (left + right) // 2 left < right left right i = 1 i 1 track = 0 track 0 for w in W:
        # if center == 26:
        #     print('track: ' + str(track))
        track += w
        if track > center:
            track = w
            i += 1
            if i > k:
                left = center + 1
                break
    else:
        right = center
     w W track += w track w if track > center:
            track = w
            i += 1
            if i > k:
                left = center + 1
                break
     track > center track center track = w track w i += 1 i 1 if i > k:
                left = center + 1
                break
     i > k i k left = center + 1 left center + 1 center 1 break right = center right center center = (left + right) // 2 center (left + right) // 2 left + right left right 2 print(center) print center center = (left + right) // 2 (left + right) // 2 center right = center center right right = sum(W) sum(W) right left = center + 1 center + 1 left left = max(math.ceil(sum(W) / k), max(W)) max(math.ceil(sum(W) / k), max(W)) left k = map(int, input().split()) map(int, input().split()) k track = w w track i = 1 1 i track += w w track center = (left + right) // 2 (left + right) // 2 center n, k = map(int, input().split()) map(int, input().split()) n W = collections.deque() collections.deque() W track = 0 0 track i += 1 1 i
import math
import collections
n, k = map(int, input().split())
W = collections.deque()
for i in range(n):
    W.append(int(input()))
left = max(math.ceil(sum(W) / k), max(W))
right = sum(W)
center = (left + right) // 2
# print('------')
while left < right:
    i = 1
    track = 0
    # print(center)
    for w in W:
        # if center == 26:
        #     print('track: ' + str(track))
        track += w
        if track > center:
            track = w
            i += 1
            if i > k:
                left = center + 1
                break
    else:
        right = center
    center = (left + right) // 2
print(center)
