def check_p(p):

    global k, ws

    ct, nt = 0, 1

    for w in ws:

        if ct + w <= p:

            ct += w

        else:

            nt += 1

            if nt > k:

                return False

            ct = w

    return True





n, k = list(map(int, input().split()))



ws = [int(eval(input())) for _ in range(n)]

l, r, p = max(ws), sum(ws), 0



while l < r:

    p = (l + r) // 2

    if check_p(p):

        r = p

    else:

        l = p = p + 1



print(p)
def check_p(p):

    global k, ws

    lt, nt = 0, 1  # loadage_of_current_truck, num_of_truck

    for w in ws:

        lt += w

        if lt > p:

            nt += 1

            if nt > k:

                return False

            lt = w

    return True





n, k = list(map(int, input().split()))



ws = [int(eval(input())) for _ in range(n)]

l, r, p = max(ws), sum(ws), 0



while l < r:

    p = (l + r) // 2

    if check_p(p):

        r = p

    else:

        l = p = p + 1



print(p)
def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True


n, k = list(map(int, input().split()))
ws = [int(eval(input())) for _ in range(n)]
l, r, p = max(ws), sum(ws), 0
while l < r:
    p = (l + r) // 2
    if check_p(p):
        r = p
    else:
        l = p = p + 1
print(p)

def check_p(p):
    global k, ws
    lt, nt = 0, 1  # loadage_of_current_truck, num_of_truck
    for w in ws:
        lt += w
        if lt > p:
            nt += 1
            if nt > k:
                return False
            lt = w
    return True


n, k = list(map(int, input().split()))
ws = [int(eval(input())) for _ in range(n)]
l, r, p = max(ws), sum(ws), 0
while l < r:
    p = (l + r) // 2
    if check_p(p):
        r = p
    else:
        l = p = p + 1
print(p)

-    ct, nt = 0, 1 +    lt, nt = 0, 1  # loadage_of_current_truck, num_of_truck -        if ct + w <= p: -            ct += w -        else: +        lt += w +        if lt > p: -            ct = w +            lt = w