n, k = [int(_) for _ in input().split()]
ary = [int(input()) for _ in range(n)]


def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1


max_p = n * 10000
ps = range(max_p + 1)
left = 0
right = max_p

while left + 1 < right:
    mid = (left + right) // 2
    v = search_v(ps[mid])

    if v >= n:
        right = mid
    else:
        left = mid

print(ps[right])
 int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ n, k = [int(_) for _ in input().split()] n [int(_) for _ in input().split()] k int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input ary = [int(input()) for _ in range(n)] ary [int(input()) for _ in range(n)] def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1 search_v v = 0 v 0 w = 0 w 0 tmp_k = 1 tmp_k 1 ind = 0 ind 0 while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1 True if tmp_k > k:
            return v
         tmp_k > k tmp_k k return v v if ind == n:
            return n

         ind == n ind n return n n tmp = ary[ind] tmp ary[ind] ary ind if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1 w + tmp <= p w + tmp w tmp p w += tmp w tmp v += 1 v 1 ind += 1 ind 1 w = 0 w 0 tmp_k += 1 tmp_k 1 p p max_p = n * 10000 max_p n * 10000 n 10000 ps = range(max_p + 1) ps range(max_p + 1) range max_p + 1 max_p 1 left = 0 left 0 right = max_p right max_p while left + 1 < right:
    mid = (left + right) // 2
    v = search_v(ps[mid])

    if v >= n:
        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 v = search_v(ps[mid]) v search_v(ps[mid]) search_v ps[mid] ps mid if v >= n:
        right = mid
    else:
        left = mid v >= n v n right = mid right mid left = mid left mid print(ps[right]) print ps[right] ps right max_p = n * 10000 n * 10000 max_p n, k = [int(_) for _ in input().split()] [int(_) for _ in input().split()] n ary = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] ary right = mid mid right ps = range(max_p + 1) range(max_p + 1) ps left = 0 0 left mid = (left + right) // 2 (left + right) // 2 mid def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1 def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1 search_v right = max_p max_p right v = search_v(ps[mid]) search_v(ps[mid]) v left = mid mid left k = [int(_) for _ in input().split()] [int(_) for _ in input().split()] k
n, k = [int(_) for _ in input().split()]
ary = [int(input()) for _ in range(n)]


def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1


max_p = n * 10000
ps = range(max_p + 1)
left = 0
right = max_p

while left + 1 < right:
    mid = (left + right) // 2
    v = search_v(ps[mid])

    if v >= n:
        right = mid
    else:
        left = mid

print(ps[right])

