def decode():
    [n, k] = [int(x) for x in input().split(" ")]
    ws = []
    for _ in range(n):
        ws.append(int(input()))

    return n, k, ws


def check(k, ws, p):
    sum_w = ws[0]
    tr = 1

    for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

    return True


if __name__ == '__main__':
    n, k, ws = decode()

    lo = max(ws)
    hi = sum(ws)

    while lo <= hi:
        p = (lo + hi) // 2

        if check(k, ws, p):
            hi = p - 1
            ans = p
        else:
            lo = p + 1

    print(ans) def decode():
    [n, k] = [int(x) for x in input().split(" ")]
    ws = []
    for _ in range(n):
        ws.append(int(input()))

    return n, k, ws decode int(x) for x in input().split(" ") for x in input().split(" ") x input().split(" ") ().split () input split " " for x in input().split(" ") int(x) int x [n, k] = [int(x) for x in input().split(" ")] [n, k] n k [int(x) for x in input().split(" ")] ws = [] ws [] for _ in range(n):
        ws.append(int(input()))

     _ range(n) range n ws.append(int(input())) ws.append ws append int(input()) int input() input return n, k, ws return n, k, ws n k ws def check(k, ws, p):
    sum_w = ws[0]
    tr = 1

    for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

    return True check sum_w = ws[0] sum_w ws[0] ws 0 tr = 1 tr 1 for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

     w ws[1:] ws 1: 1 if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

     sum_w + w <= p sum_w + w sum_w w p sum_w += w sum_w w sum_w = w sum_w w tr += 1 tr 1 if tr > k:
                return False

     tr > k tr k return False False return True True k k ws ws p p if __name__ == '__main__':
    n, k, ws = decode()

    lo = max(ws)
    hi = sum(ws)

    while lo <= hi:
        p = (lo + hi) // 2

        if check(k, ws, p):
            hi = p - 1
            ans = p
        else:
            lo = p + 1

    print(ans) __name__ == '__main__' __name__ '__main__' n, k, ws = decode() n decode() decode k ws lo = max(ws) lo max(ws) max ws hi = sum(ws) hi sum(ws) sum ws while lo <= hi:
        p = (lo + hi) // 2

        if check(k, ws, p):
            hi = p - 1
            ans = p
        else:
            lo = p + 1

     lo <= hi lo hi p = (lo + hi) // 2 p (lo + hi) // 2 lo + hi lo hi 2 if check(k, ws, p):
            hi = p - 1
            ans = p
        else:
            lo = p + 1

     check(k, ws, p) check k ws p hi = p - 1 hi p - 1 p 1 ans = p ans p lo = p + 1 lo p + 1 p 1 print(ans) print ans ws = decode() decode() ws lo = p + 1 p + 1 lo ans = p p ans hi = p - 1 p - 1 hi k, ws = decode() decode() k lo = max(ws) max(ws) lo def decode():
    [n, k] = [int(x) for x in input().split(" ")]
    ws = []
    for _ in range(n):
        ws.append(int(input()))

    return n, k, ws def decode():
    [n, k] = [int(x) for x in input().split(" ")]
    ws = []
    for _ in range(n):
        ws.append(int(input()))

    return n, k, ws decode def check(k, ws, p):
    sum_w = ws[0]
    tr = 1

    for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

    return True def check(k, ws, p):
    sum_w = ws[0]
    tr = 1

    for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

    return True check n, k, ws = decode() decode() n hi = sum(ws) sum(ws) hi p = (lo + hi) // 2 (lo + hi) // 2 p
def decode():
    [n, k] = [int(x) for x in input().split(" ")]
    ws = []
    for _ in range(n):
        ws.append(int(input()))

    return n, k, ws


def check(k, ws, p):
    sum_w = ws[0]
    tr = 1

    for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

    return True


if __name__ == '__main__':
    n, k, ws = decode()

    lo = max(ws)
    hi = sum(ws)

    while lo <= hi:
        p = (lo + hi) // 2

        if check(k, ws, p):
            hi = p - 1
            ans = p
        else:
            lo = p + 1

    print(ans)
