def is_ok(W, limit_num, track_num):
    cu_vol = 0
    cu_tr = 0
    
    for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
    if cu_vol:
        cu_tr += 1
    
    return track_num >= cu_tr

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

top = max(W)
tail = sum(W)
limit_num = 0

while top < tail:
    limit_num = (top + tail) // 2
    if is_ok(W, limit_num, k):
        tail = limit_num
    else:
        top = limit_num + 1

print(tail)

 def is_ok(W, limit_num, track_num):
    cu_vol = 0
    cu_tr = 0
    
    for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
    if cu_vol:
        cu_tr += 1
    
    return track_num >= cu_tr is_ok cu_vol = 0 cu_vol 0 cu_tr = 0 cu_tr 0 for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
     i range(len(W)) range len(W) len W if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
     cu_vol + W[i] > limit_num cu_vol + W[i] cu_vol W[i] W i limit_num cu_vol = W[i] cu_vol W[i] W i cu_tr += 1 cu_tr 1 cu_vol += W[i] cu_vol W[i] W i if cu_vol:
        cu_tr += 1
    
     cu_vol cu_tr += 1 cu_tr 1 return track_num >= cu_tr track_num >= cu_tr track_num cu_tr W W limit_num limit_num track_num track_num int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, k = [int(i) for i in input().split()] n [int(i) for i in 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)] top = max(W) top max(W) max W tail = sum(W) tail sum(W) sum W limit_num = 0 limit_num 0 while top < tail:
    limit_num = (top + tail) // 2
    if is_ok(W, limit_num, k):
        tail = limit_num
    else:
        top = limit_num + 1 top < tail top tail limit_num = (top + tail) // 2 limit_num (top + tail) // 2 top + tail top tail 2 if is_ok(W, limit_num, k):
        tail = limit_num
    else:
        top = limit_num + 1 is_ok(W, limit_num, k) is_ok W limit_num k tail = limit_num tail limit_num top = limit_num + 1 top limit_num + 1 limit_num 1 print(tail) print tail top = max(W) max(W) top limit_num = (top + tail) // 2 (top + tail) // 2 limit_num top = limit_num + 1 limit_num + 1 top n, k = [int(i) for i in input().split()] [int(i) for i in input().split()] n W = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W def is_ok(W, limit_num, track_num):
    cu_vol = 0
    cu_tr = 0
    
    for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
    if cu_vol:
        cu_tr += 1
    
    return track_num >= cu_tr def is_ok(W, limit_num, track_num):
    cu_vol = 0
    cu_tr = 0
    
    for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
    if cu_vol:
        cu_tr += 1
    
    return track_num >= cu_tr is_ok tail = limit_num limit_num tail tail = sum(W) sum(W) tail k = [int(i) for i in input().split()] [int(i) for i in input().split()] k limit_num = 0 0 limit_num
def is_ok(W, limit_num, track_num):
    cu_vol = 0
    cu_tr = 0
    
    for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
    if cu_vol:
        cu_tr += 1
    
    return track_num >= cu_tr

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

top = max(W)
tail = sum(W)
limit_num = 0

while top < tail:
    limit_num = (top + tail) // 2
    if is_ok(W, limit_num, k):
        tail = limit_num
    else:
        top = limit_num + 1

print(tail)


