def ok(m):
    c = 1
    tmp = m
    for w in W:
        if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
    return k >= c

n, k = map(int, input().split())
W = [int(input()) for i in range(n)]

left = max(W)
right = sum(W)+1
while left+1 < right:
    mid = (left+right) // 2
    if ok(mid):
        right = mid
    else:
        left = mid
print(left) def ok(m):
    c = 1
    tmp = m
    for w in W:
        if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
    return k >= c ok c = 1 c 1 tmp = m tmp m for w in W:
        if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
     w W if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
     tmp > w tmp w tmp -= w tmp w c += 1 c 1 tmp = m - w tmp m - w m w return k >= c k >= c k c m m n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input W = [int(input()) for i in range(n)] W [int(input()) for i in range(n)] left = max(W) left max(W) max W right = sum(W)+1 right sum(W)+1 sum(W) sum W 1 while left+1 < right:
    mid = (left+right) // 2
    if ok(mid):
        right = mid
    else:
        left = mid left+1 < right left+1 left 1 right mid = (left+right) // 2 mid (left+right) // 2 left+right left right 2 if ok(mid):
        right = mid
    else:
        left = mid ok(mid) ok mid right = mid right mid left = mid left mid print(left) print left left = max(W) max(W) left right = sum(W)+1 sum(W)+1 right n, k = map(int, input().split()) map(int, input().split()) n right = mid mid right mid = (left+right) // 2 (left+right) // 2 mid left = mid mid left def ok(m):
    c = 1
    tmp = m
    for w in W:
        if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
    return k >= c def ok(m):
    c = 1
    tmp = m
    for w in W:
        if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
    return k >= c ok k = map(int, input().split()) map(int, input().split()) k W = [int(input()) for i in range(n)] [int(input()) for i in range(n)] W
def ok(m):
    c = 1
    tmp = m
    for w in W:
        if tmp > w:
            tmp -= w
        else:
            c += 1
            tmp = m - w
    return k >= c

n, k = map(int, input().split())
W = [int(input()) for i in range(n)]

left = max(W)
right = sum(W)+1
while left+1 < right:
    mid = (left+right) // 2
    if ok(mid):
        right = mid
    else:
        left = mid
print(left)
