def ok(P):
    cnt = 0
    truck = 0
    for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
    if cnt + 1 <= K:
        return True
    else:
        return False


N, K = map(int, input().split())
W = [int(input()) for _ in range(N)]
l, r = 0, 10**10
while r - l > 1:
    c = (l + r) // 2
    if ok(c):
        r = c
    else:
        l = c
print(r)
 def ok(P):
    cnt = 0
    truck = 0
    for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
    if cnt + 1 <= K:
        return True
    else:
        return False ok cnt = 0 cnt 0 truck = 0 truck 0 for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
     w W + [0] W [0] 0 if w > P:
            return False
         w > P w P return False False if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
     truck + w <= P truck + w truck w P truck += w truck w truck = w truck w cnt += 1 cnt 1 if cnt + 1 <= K:
        return True
    else:
        return False cnt + 1 <= K cnt + 1 cnt 1 K return True True return False False 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)] l, r = 0, 10**10 l 0 r 10**10 10 10 while r - l > 1:
    c = (l + r) // 2
    if ok(c):
        r = c
    else:
        l = c r - l > 1 r - l r l 1 c = (l + r) // 2 c (l + r) // 2 l + r l r 2 if ok(c):
        r = c
    else:
        l = c ok(c) ok c r = c r c l = c l c print(r) print r N, K = map(int, input().split()) map(int, input().split()) N l = c c l r = 0, 10**10 10**10 r def ok(P):
    cnt = 0
    truck = 0
    for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
    if cnt + 1 <= K:
        return True
    else:
        return False def ok(P):
    cnt = 0
    truck = 0
    for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
    if cnt + 1 <= K:
        return True
    else:
        return False ok c = (l + r) // 2 (l + r) // 2 c r = c c r W = [int(input()) for _ in range(N)] [int(input()) for _ in range(N)] W K = map(int, input().split()) map(int, input().split()) K l, r = 0, 10**10 0 l
def ok(P):
    cnt = 0
    truck = 0
    for w in W + [0]:
        if w > P:
            return False
        if truck + w <= P:
            truck += w
        else:
            truck = w
            cnt += 1
    if cnt + 1 <= K:
        return True
    else:
        return False


N, K = map(int, input().split())
W = [int(input()) for _ in range(N)]
l, r = 0, 10**10
while r - l > 1:
    c = (l + r) // 2
    if ok(c):
        r = c
    else:
        l = c
print(r)

