import sys

readline = sys.stdin.readline

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

v = [int(readline()) for _ in range(n)]

lo = max(v) - 1

hi = sum(v)

while hi - lo > 1:

    p = P = (lo + hi) // 2

    m = 1

    for i in range(n):

        if v[i] > p:

            p = P

            m += 1

        p -= v[i]

    if m <= k:

        hi = P

    else:

        lo = P

print(hi)



import sys

readline = sys.stdin.readline

N, K = list(map(int, input().split()))

W = tuple(int(readline()) for _ in range(N))

ma = max(W)

def check(x):

    if x < ma:

        return False

    use = 1

    rest = x

    for w in W:

        if rest >= w:

            rest -= w

        else:

            rest = x - w

            use += 1

    return use <= K

l = 0

r = sum(W)

while r - l > 1:

    m = (r + l) // 2

    if check(m):

        r = m

    else:

        l = m

print(r)

import sys

readline = sys.stdin.readline
n, k = list(map(int, readline().split()))
v = [int(readline()) for _ in range(n)]
lo = max(v) - 1
hi = sum(v)
while hi - lo > 1:
    p = P = (lo + hi) // 2
    m = 1
    for i in range(n):
        if v[i] > p:
            p = P
            m += 1
        p -= v[i]
    if m <= k:
        hi = P
    else:
        lo = P
print(hi)

import sys

readline = sys.stdin.readline
N, K = list(map(int, input().split()))
W = tuple(int(readline()) for _ in range(N))
ma = max(W)


def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K


l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

-n, k = list(map(int, readline().split())) -v = [int(readline()) for _ in range(n)] -lo = max(v) - 1 -hi = sum(v) -while hi - lo > 1: -    p = P = (lo + hi) // 2 -    m = 1 -    for i in range(n): -        if v[i] > p: -            p = P -            m += 1 -        p -= v[i] -    if m <= k: -        hi = P +N, K = list(map(int, input().split())) +W = tuple(int(readline()) for _ in range(N)) +ma = max(W) + + +def check(x): +    if x < ma: +        return False +    use = 1 +    rest = x +    for w in W: +        if rest >= w: +            rest -= w +        else: +            rest = x - w +            use += 1 +    return use <= K + + +l = 0 +r = sum(W) +while r - l > 1: +    m = (r + l) // 2 +    if check(m): +        r = m -        lo = P -print(hi) +        l = m +print(r)