def ok(p, ws, n, k):
    track = 1
    now = 0
    for i in range(n):
        if ws[i] > p:
            return False
        if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
    if track > k:
        return False
    else:
        return True


nk = input().split()
n = int(nk[0])
k = int(nk[1])
ws = []
for _ in range(n):
    ws.append(int(input()))

p_min = 0
p_max = int(1e+10)
while p_min < p_max:
    p = (p_min + p_max) // 2
    if ok(p, ws, n, k):
        p_max = p
    else:
        p_min = p + 1
print(p_max) def ok(p, ws, n, k):
    track = 1
    now = 0
    for i in range(n):
        if ws[i] > p:
            return False
        if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
    if track > k:
        return False
    else:
        return True ok track = 1 track 1 now = 0 now 0 for i in range(n):
        if ws[i] > p:
            return False
        if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
     i range(n) range n if ws[i] > p:
            return False
         ws[i] > p ws[i] ws i p return False False if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
     now + ws[i] > p now + ws[i] now ws[i] ws i p track += 1 track 1 now = ws[i] now ws[i] ws i now += ws[i] now ws[i] ws i if track > k:
        return False
    else:
        return True track > k track k return False False return True True p p ws ws n n k k nk = input().split() nk input().split() ().split () input split n = int(nk[0]) n int(nk[0]) int nk[0] nk 0 k = int(nk[1]) k int(nk[1]) int nk[1] nk 1 ws = [] ws [] for _ in range(n):
    ws.append(int(input())) _ range(n) range n ws.append(int(input())) ws.append ws append int(input()) int input() input p_min = 0 p_min 0 p_max = int(1e+10) p_max int(1e+10) int 1e+10 while p_min < p_max:
    p = (p_min + p_max) // 2
    if ok(p, ws, n, k):
        p_max = p
    else:
        p_min = p + 1 p_min < p_max p_min p_max p = (p_min + p_max) // 2 p (p_min + p_max) // 2 p_min + p_max p_min p_max 2 if ok(p, ws, n, k):
        p_max = p
    else:
        p_min = p + 1 ok(p, ws, n, k) ok p ws n k p_max = p p_max p p_min = p + 1 p_min p + 1 p 1 print(p_max) print p_max p = (p_min + p_max) // 2 (p_min + p_max) // 2 p p_max = int(1e+10) int(1e+10) p_max n = int(nk[0]) int(nk[0]) n p_min = 0 0 p_min p_min = p + 1 p + 1 p_min nk = input().split() input().split() nk ws = [] [] ws def ok(p, ws, n, k):
    track = 1
    now = 0
    for i in range(n):
        if ws[i] > p:
            return False
        if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
    if track > k:
        return False
    else:
        return True def ok(p, ws, n, k):
    track = 1
    now = 0
    for i in range(n):
        if ws[i] > p:
            return False
        if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
    if track > k:
        return False
    else:
        return True ok p_max = p p p_max k = int(nk[1]) int(nk[1]) k
def ok(p, ws, n, k):
    track = 1
    now = 0
    for i in range(n):
        if ws[i] > p:
            return False
        if now + ws[i] > p:
            track += 1
            now = ws[i]
        else:
            now += ws[i]
    if track > k:
        return False
    else:
        return True


nk = input().split()
n = int(nk[0])
k = int(nk[1])
ws = []
for _ in range(n):
    ws.append(int(input()))

p_min = 0
p_max = int(1e+10)
while p_min < p_max:
    p = (p_min + p_max) // 2
    if ok(p, ws, n, k):
        p_max = p
    else:
        p_min = p + 1
print(p_max)
