import math
n, k = map(int, input().split())
num = [int(input()) for i in range(n)]
#num.sort()
left = max(max(num), math.ceil(sum(num)/k))
right = sum(num)
while left < right:
    mid = (left + right) // 2
    track = 1
    cnt = 0
    flag = 0
    for i in num:
        cnt += i
        if cnt > mid:
            track+=1
            cnt = i
        if track > k:
            flag = 1
            break
        if flag:
            break
    if flag == 0:
        right = mid
    else:
        left = mid+1
print(left) import math math n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k 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 num = [int(input()) for i in range(n)] num [int(input()) for i in range(n)] left = max(max(num), math.ceil(sum(num)/k)) left max(max(num), math.ceil(sum(num)/k)) max max(num) max num math.ceil(sum(num)/k) math.ceil math ceil sum(num)/k sum(num) sum num k right = sum(num) right sum(num) sum num while left < right:
    mid = (left + right) // 2
    track = 1
    cnt = 0
    flag = 0
    for i in num:
        cnt += i
        if cnt > mid:
            track+=1
            cnt = i
        if track > k:
            flag = 1
            break
        if flag:
            break
    if flag == 0:
        right = mid
    else:
        left = mid+1 left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 track = 1 track 1 cnt = 0 cnt 0 flag = 0 flag 0 for i in num:
        cnt += i
        if cnt > mid:
            track+=1
            cnt = i
        if track > k:
            flag = 1
            break
        if flag:
            break
     i num cnt += i cnt i if cnt > mid:
            track+=1
            cnt = i
         cnt > mid cnt mid track+=1 track 1 cnt = i cnt i if track > k:
            flag = 1
            break
         track > k track k flag = 1 flag 1 break if flag:
            break
     flag break if flag == 0:
        right = mid
    else:
        left = mid+1 flag == 0 flag 0 right = mid right mid left = mid+1 left mid+1 mid 1 print(left) print left num = [int(input()) for i in range(n)] [int(input()) for i in range(n)] num flag = 0 0 flag track = 1 1 track mid = (left + right) // 2 (left + right) // 2 mid right = mid mid right left = mid+1 mid+1 left cnt += i i cnt right = sum(num) sum(num) right cnt = i i cnt n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k left = max(max(num), math.ceil(sum(num)/k)) max(max(num), math.ceil(sum(num)/k)) left cnt = 0 0 cnt flag = 1 1 flag track+=1 1 track
import math
n, k = map(int, input().split())
num = [int(input()) for i in range(n)]
#num.sort()
left = max(max(num), math.ceil(sum(num)/k))
right = sum(num)
while left < right:
    mid = (left + right) // 2
    track = 1
    cnt = 0
    flag = 0
    for i in num:
        cnt += i
        if cnt > mid:
            track+=1
            cnt = i
        if track > k:
            flag = 1
            break
        if flag:
            break
    if flag == 0:
        right = mid
    else:
        left = mid+1
print(left)
