#ALDS1_4_D Allocaion
def check(k, w, p):  # 積載制限 p 台数 k のトラックに乗り切るか確認
    j = 0
    for i in range(k):
        sum = 0
        while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
        if j == len(w):
            break

    if j == len(w):
        return True
    else:
        return False


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

left = sum(w) // k - 1
right = left + max(w)

while True:
    mid = (left + right) // 2
    # print('mid : {}'.format(mid))

    if check(k, w, mid):
        right = mid
    else:
        left = mid
    if right - left <= 1:
        break
    # print('left : {}  right : {}'.format(left, right))

print(right)
 def check(k, w, p):  # 積載制限 p 台数 k のトラックに乗り切るか確認
    j = 0
    for i in range(k):
        sum = 0
        while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
        if j == len(w):
            break

    if j == len(w):
        return True
    else:
        return False check j = 0 j 0 for i in range(k):
        sum = 0
        while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
        if j == len(w):
            break

     i range(k) range k sum = 0 sum 0 while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
         sum < p sum p if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
             sum + w[j] > p sum + w[j] sum w[j] w j p break sum += w[j] sum w[j] w j j += 1 j 1 if j == len(w):  # 積載完了
                break
         j == len(w) j len(w) len w break if j == len(w):
            break

     j == len(w) j len(w) len w break if j == len(w):
        return True
    else:
        return False j == len(w) j len(w) len w return True True return False False k k w w p p n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () 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)] left = sum(w) // k - 1 left sum(w) // k - 1 sum(w) // k sum(w) sum w k 1 right = left + max(w) right left + max(w) left max(w) max w while True:
    mid = (left + right) // 2
    # print('mid : {}'.format(mid))

    if check(k, w, mid):
        right = mid
    else:
        left = mid
    if right - left <= 1:
        break
    # print('left : {}  right : {}'.format(left, right)) True mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if check(k, w, mid):
        right = mid
    else:
        left = mid
     check(k, w, mid) check k w mid right = mid right mid left = mid left mid if right - left <= 1:
        break
    # print('left : {}  right : {}'.format(left, right)) right - left <= 1 right - left right left 1 break print(right) print right left = mid mid left n, k = map(int, input().split()) map(int, input().split()) n left = sum(w) // k - 1 sum(w) // k - 1 left mid = (left + right) // 2 (left + right) // 2 mid k = map(int, input().split()) map(int, input().split()) k right = left + max(w) left + max(w) right w = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] w def check(k, w, p):  # 積載制限 p 台数 k のトラックに乗り切るか確認
    j = 0
    for i in range(k):
        sum = 0
        while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
        if j == len(w):
            break

    if j == len(w):
        return True
    else:
        return False def check(k, w, p):  # 積載制限 p 台数 k のトラックに乗り切るか確認
    j = 0
    for i in range(k):
        sum = 0
        while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
        if j == len(w):
            break

    if j == len(w):
        return True
    else:
        return False check right = mid mid right
#ALDS1_4_D Allocaion
def check(k, w, p):  # 積載制限 p 台数 k のトラックに乗り切るか確認
    j = 0
    for i in range(k):
        sum = 0
        while sum < p:
            if sum + w[j] > p:
                break
            else:
                sum += w[j]
                j += 1
            if j == len(w):  # 積載完了
                break
        if j == len(w):
            break

    if j == len(w):
        return True
    else:
        return False


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

left = sum(w) // k - 1
right = left + max(w)

while True:
    mid = (left + right) // 2
    # print('mid : {}'.format(mid))

    if check(k, w, mid):
        right = mid
    else:
        left = mid
    if right - left <= 1:
        break
    # print('left : {}  right : {}'.format(left, right))

print(right)

