import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = tuple(int(readline()) for _ in range(N))
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K
l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r) import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K W = tuple(int(readline()) for _ in range(N)) W tuple(int(readline()) for _ in range(N)) tuple int(readline()) int readline() readline ma = max(W) ma max(W) max W def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K check if x < ma:
        return False
     x < ma x ma return False False use = 1 use 1 rest = x rest x for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
     w W if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
     rest >= w rest w rest -= w rest w rest = x - w rest x - w x w use += 1 use 1 return use <= K use <= K use K x x l = 0 l 0 r = sum(W) r sum(W) sum W while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m r - l > 1 r - l r l 1 m = (r + l) // 2 m (r + l) // 2 r + l r l 2 if check(m):
        r = m
    else:
        l = m check(m) check m r = m r m l = m l m print(r) print r N, K = map(int, input().split()) map(int, input().split()) N l = m m l readline = sys.stdin.readline sys.stdin.readline readline m = (r + l) // 2 (r + l) // 2 m K = map(int, input().split()) map(int, input().split()) K W = tuple(int(readline()) for _ in range(N)) tuple(int(readline()) for _ in range(N)) W def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K check ma = max(W) max(W) ma r = sum(W) sum(W) r r = m m r l = 0 0 l
import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = tuple(int(readline()) for _ in range(N))
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K
l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)
