import sys
n,k = map(int,input().split())
input = sys.stdin.readline
W = [int(input()) for i in range(n)]
l = max(W)-1
W.append(10**13)
h = sum(W)
while l+1 < h:
    ok = (l+h)//2
    track = 0
    cur = 0
    for i in range(n+1):
        cur += W[i]
        if cur > ok:
            track += 1
            cur = W[i]
        elif cur == ok:
            if i != n-1:
                track += 1
                cur = 0
    if track > k:
        l = ok
    else:
        h = ok
print(h) import sys sys n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input W = [int(input()) for i in range(n)] W [int(input()) for i in range(n)] l = max(W)-1 l max(W)-1 max(W) max W 1 W.append(10**13) W.append W append 10**13 10 13 h = sum(W) h sum(W) sum W while l+1 < h:
    ok = (l+h)//2
    track = 0
    cur = 0
    for i in range(n+1):
        cur += W[i]
        if cur > ok:
            track += 1
            cur = W[i]
        elif cur == ok:
            if i != n-1:
                track += 1
                cur = 0
    if track > k:
        l = ok
    else:
        h = ok l+1 < h l+1 l 1 h ok = (l+h)//2 ok (l+h)//2 l+h l h 2 track = 0 track 0 cur = 0 cur 0 for i in range(n+1):
        cur += W[i]
        if cur > ok:
            track += 1
            cur = W[i]
        elif cur == ok:
            if i != n-1:
                track += 1
                cur = 0
     i range(n+1) range n+1 n 1 cur += W[i] cur W[i] W i if cur > ok:
            track += 1
            cur = W[i]
        elif cur == ok:
            if i != n-1:
                track += 1
                cur = 0
     cur > ok cur ok track += 1 track 1 cur = W[i] cur W[i] W i elif cur == ok:
            if i != n-1:
                track += 1
                cur = 0
     cur == ok cur ok if i != n-1:
                track += 1
                cur = 0
     i != n-1 i n-1 n 1 track += 1 track 1 cur = 0 cur 0 if track > k:
        l = ok
    else:
        h = ok track > k track k l = ok l ok h = ok h ok print(h) print h k = map(int,input().split()) map(int,input().split()) k cur = 0 0 cur h = sum(W) sum(W) h n,k = map(int,input().split()) map(int,input().split()) n track = 0 0 track track += 1 1 track l = ok ok l input = sys.stdin.readline sys.stdin.readline input cur += W[i] W[i] cur h = ok ok h cur = W[i] W[i] cur ok = (l+h)//2 (l+h)//2 ok track += 1 1 track W = [int(input()) for i in range(n)] [int(input()) for i in range(n)] W l = max(W)-1 max(W)-1 l cur = 0 0 cur
import sys
n,k = map(int,input().split())
input = sys.stdin.readline
W = [int(input()) for i in range(n)]
l = max(W)-1
W.append(10**13)
h = sum(W)
while l+1 < h:
    ok = (l+h)//2
    track = 0
    cur = 0
    for i in range(n+1):
        cur += W[i]
        if cur > ok:
            track += 1
            cur = W[i]
        elif cur == ok:
            if i != n-1:
                track += 1
                cur = 0
    if track > k:
        l = ok
    else:
        h = ok
print(h)
