def check(k, W, p):
    s = 0
    count = 1
    for w in W:
        if s + w > p:
            count += 1
            s = 0
        s += w
    return count <= k

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

right = sum(W)
left = max(right // k, max(W)) - 1
while right - left > 1:
    p = (left + right) // 2
    if check(k, W, p):
        right = p
    else:
        left = p
print(right) def check(k, W, p):
    s = 0
    count = 1
    for w in W:
        if s + w > p:
            count += 1
            s = 0
        s += w
    return count <= k check s = 0 s 0 count = 1 count 1 for w in W:
        if s + w > p:
            count += 1
            s = 0
        s += w
     w W if s + w > p:
            count += 1
            s = 0
         s + w > p s + w s w p count += 1 count 1 s = 0 s 0 s += w s w return count <= k count <= k count k k k W W p p n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () 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 W = [int(input()) for _ in range(n)] W [int(input()) for _ in range(n)] right = sum(W) right sum(W) sum W left = max(right // k, max(W)) - 1 left max(right // k, max(W)) - 1 max(right // k, max(W)) max right // k right k max(W) max W 1 while right - left > 1:
    p = (left + right) // 2
    if check(k, W, p):
        right = p
    else:
        left = p right - left > 1 right - left right left 1 p = (left + right) // 2 p (left + right) // 2 left + right left right 2 if check(k, W, p):
        right = p
    else:
        left = p check(k, W, p) check k W p right = p right p left = p left p print(right) print right W = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W n, k = map(int, input().split()) map(int, input().split()) n p = (left + right) // 2 (left + right) // 2 p def check(k, W, p):
    s = 0
    count = 1
    for w in W:
        if s + w > p:
            count += 1
            s = 0
        s += w
    return count <= k def check(k, W, p):
    s = 0
    count = 1
    for w in W:
        if s + w > p:
            count += 1
            s = 0
        s += w
    return count <= k check left = max(right // k, max(W)) - 1 max(right // k, max(W)) - 1 left right = p p right left = p p left k = map(int, input().split()) map(int, input().split()) k right = sum(W) sum(W) right
def check(k, W, p):
    s = 0
    count = 1
    for w in W:
        if s + w > p:
            count += 1
            s = 0
        s += w
    return count <= k

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

right = sum(W)
left = max(right // k, max(W)) - 1
while right - left > 1:
    p = (left + right) // 2
    if check(k, W, p):
        right = p
    else:
        left = p
print(right)
