# -*- coding: utf-8 -*-
N, k = [int(n) for n in input().split()]
W = []

def search(W, k, P):
    tmp = 0
    track = 1
    for w in W:
        if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
    if track > k:
        return False
    else:
        return True         
        

for n in range(N):
    W.append(int(input()))

left = max(sum(W) // N, max(W))
right = sum(W)

while right - left > 1 :
    mid = (left + right)//2
    if search(W, k, mid):
        right = mid
    else:
        left = mid
    
if search(W, k, left):
    print(left)
else:
    print(right)   int(n) for n in input().split() for n in input().split() n input().split() ().split () input split for n in input().split() int(n) int n N, k = [int(n) for n in input().split()] N [int(n) for n in input().split()] k W = [] W [] def search(W, k, P):
    tmp = 0
    track = 1
    for w in W:
        if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
    if track > k:
        return False
    else:
        return True         
         search tmp = 0 tmp 0 track = 1 track 1 for w in W:
        if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
     w W if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
     tmp + w <= P tmp + w tmp w P tmp += w tmp w track += 1 track 1 tmp = w tmp w if track > k:
        return False
    else:
        return True         
         track > k track k return False False return True True W W k k P P for n in range(N):
    W.append(int(input())) n range(N) range N W.append(int(input())) W.append W append int(input()) int input() input left = max(sum(W) // N, max(W)) left max(sum(W) // N, max(W)) max sum(W) // N sum(W) sum W N max(W) max W right = sum(W) right sum(W) sum W while right - left > 1 :
    mid = (left + right)//2
    if search(W, k, mid):
        right = mid
    else:
        left = mid
     right - left > 1 right - left right left 1 mid = (left + right)//2 mid (left + right)//2 left + right left right 2 if search(W, k, mid):
        right = mid
    else:
        left = mid
     search(W, k, mid) search W k mid right = mid right mid left = mid left mid if search(W, k, left):
    print(left)
else:
    print(right)   search(W, k, left) search W k left print(left) print left print(right) print right def search(W, k, P):
    tmp = 0
    track = 1
    for w in W:
        if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
    if track > k:
        return False
    else:
        return True         
         def search(W, k, P):
    tmp = 0
    track = 1
    for w in W:
        if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
    if track > k:
        return False
    else:
        return True         
         search right = mid mid right N, k = [int(n) for n in input().split()] [int(n) for n in input().split()] N mid = (left + right)//2 (left + right)//2 mid left = mid mid left W = [] [] W left = max(sum(W) // N, max(W)) max(sum(W) // N, max(W)) left right = sum(W) sum(W) right k = [int(n) for n in input().split()] [int(n) for n in input().split()] k
# -*- coding: utf-8 -*-
N, k = [int(n) for n in input().split()]
W = []

def search(W, k, P):
    tmp = 0
    track = 1
    for w in W:
        if tmp + w <= P:
            tmp += w
        else:
            track += 1
            tmp = w
    if track > k:
        return False
    else:
        return True         
        

for n in range(N):
    W.append(int(input()))

left = max(sum(W) // N, max(W))
right = sum(W)

while right - left > 1 :
    mid = (left + right)//2
    if search(W, k, mid):
        right = mid
    else:
        left = mid
    
if search(W, k, left):
    print(left)
else:
    print(right)  