n, k, *W = map(int, open(0).read().split())
left, right = 1000000000, max(W) - 1


def check(M):
    L = [W[0]]
    for i in range(1, n):
        if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
    return len(L) <= k


while left - right > 1:
    m = (left + right) // 2
    if check(m):
        left = m
    else:
        right = m
print(left)
 n, k, *W = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split k *W W left, right = 1000000000, max(W) - 1 left 1000000000 right max(W) - 1 max(W) max W 1 def check(M):
    L = [W[0]]
    for i in range(1, n):
        if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
    return len(L) <= k check L = [W[0]] L [W[0]] W[0] W 0 for i in range(1, n):
        if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
     i range(1, n) range 1 n if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
     L[-1] + W[i] <= M L[-1] + W[i] L[-1] L -1 W[i] W i M L[-1] += W[i] L[-1] L -1 W[i] W i L.append(W[i]) L.append L append W[i] W i return len(L) <= k len(L) <= k len(L) len L k M M while left - right > 1:
    m = (left + right) // 2
    if check(m):
        left = m
    else:
        right = m left - right > 1 left - right left right 1 m = (left + right) // 2 m (left + right) // 2 left + right left right 2 if check(m):
        left = m
    else:
        right = m check(m) check m left = m left m right = m right m print(left) print left right = m m right left, right = 1000000000, max(W) - 1 1000000000 left def check(M):
    L = [W[0]]
    for i in range(1, n):
        if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
    return len(L) <= k def check(M):
    L = [W[0]]
    for i in range(1, n):
        if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
    return len(L) <= k check left = m m left n, k, *W = map(int, open(0).read().split()) map(int, open(0).read().split()) n right = 1000000000, max(W) - 1 max(W) - 1 right k, *W = map(int, open(0).read().split()) map(int, open(0).read().split()) k m = (left + right) // 2 (left + right) // 2 m
n, k, *W = map(int, open(0).read().split())
left, right = 1000000000, max(W) - 1


def check(M):
    L = [W[0]]
    for i in range(1, n):
        if L[-1] + W[i] <= M:
            L[-1] += W[i]
        else:
            L.append(W[i])
    return len(L) <= k


while left - right > 1:
    m = (left + right) // 2
    if check(m):
        left = m
    else:
        right = m
print(left)

