n,k=map(int, input().split( ))
w = []
for _ in range(n):
    w.append(int(input()))
mx=sum(w)
mn=max(w)##mx//k<max(w)が抜けてる
mid = (mx+mn)//2
w.append(1000000000000000)

while mn < mid:#このループ条件が不自然みたいだが
    cnt = 1
    sm = 0
    for i in range(n):#ここがwhileだったのを修正して減らした
        if sm <= mid-w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt>k:
        mn = mid
        mid = (mid+mx)//2
    else:
        mx = mid
        mid = (mid+mn)//2
#最終的な実行可能解が不明、結局最後mn,mid,mx全部チェックしてる
ans=[]
for a in [mn,mid,mx]:
    cnt = 1
    sm = 0
    for i in range(n):
        if sm <= a - w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt<=k:
        ans.append(a)
    else:
        pass

print(min(ans))
#最終的な実行可能解は(直前までmidだった)mx
 n,k=map(int, input().split( )) n map(int, input().split( )) map int input().split( ) ().split () input split k w = [] w [] for _ in range(n):
    w.append(int(input())) _ range(n) range n w.append(int(input())) w.append w append int(input()) int input() input mx=sum(w) mx sum(w) sum w mn=max(w) mn max(w) max w mid = (mx+mn)//2 mid (mx+mn)//2 mx+mn mx mn 2 w.append(1000000000000000) w.append w append 1000000000000000 while mn < mid:#このループ条件が不自然みたいだが
    cnt = 1
    sm = 0
    for i in range(n):#ここがwhileだったのを修正して減らした
        if sm <= mid-w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt>k:
        mn = mid
        mid = (mid+mx)//2
    else:
        mx = mid
        mid = (mid+mn)//2
#最終的な実行可能解が不明、結局最後mn,mid,mx全部チェックしてる mn < mid mn mid cnt = 1 cnt 1 sm = 0 sm 0 for i in range(n):#ここがwhileだったのを修正して減らした
        if sm <= mid-w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

     i range(n) range n if sm <= mid-w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

     sm <= mid-w[i] sm mid-w[i] mid w[i] w i sm +=  w[i] sm w[i] w i cnt+=1 cnt 1 sm = w[i] sm w[i] w i if cnt>k:
        mn = mid
        mid = (mid+mx)//2
    else:
        mx = mid
        mid = (mid+mn)//2
#最終的な実行可能解が不明、結局最後mn,mid,mx全部チェックしてる cnt>k cnt k mn = mid mn mid mid = (mid+mx)//2 mid (mid+mx)//2 mid+mx mid mx 2 mx = mid mx mid mid = (mid+mn)//2 mid (mid+mn)//2 mid+mn mid mn 2 ans=[] ans [] for a in [mn,mid,mx]:
    cnt = 1
    sm = 0
    for i in range(n):
        if sm <= a - w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt<=k:
        ans.append(a)
    else:
        pass a [mn,mid,mx] mn mid mx cnt = 1 cnt 1 sm = 0 sm 0 for i in range(n):
        if sm <= a - w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

     i range(n) range n if sm <= a - w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

     sm <= a - w[i] sm a - w[i] a w[i] w i sm +=  w[i] sm w[i] w i cnt+=1 cnt 1 sm = w[i] sm w[i] w i if cnt<=k:
        ans.append(a)
    else:
        pass cnt<=k cnt k ans.append(a) ans.append ans append a print(min(ans)) print min(ans) min ans mn = mid mid mn cnt+=1 1 cnt cnt+=1 1 cnt mx = mid mid mx mid = (mid+mn)//2 (mid+mn)//2 mid mid = (mx+mn)//2 (mx+mn)//2 mid cnt = 1 1 cnt mx=sum(w) sum(w) mx sm = w[i] w[i] sm cnt = 1 1 cnt w = [] [] w mid = (mid+mx)//2 (mid+mx)//2 mid sm = 0 0 sm sm = 0 0 sm ans=[] [] ans mn=max(w) max(w) mn n,k=map(int, input().split( )) map(int, input().split( )) n sm +=  w[i] w[i] sm sm = w[i] w[i] sm sm +=  w[i] w[i] sm k=map(int, input().split( )) map(int, input().split( )) k
n,k=map(int, input().split( ))
w = []
for _ in range(n):
    w.append(int(input()))
mx=sum(w)
mn=max(w)##mx//k<max(w)が抜けてる
mid = (mx+mn)//2
w.append(1000000000000000)

while mn < mid:#このループ条件が不自然みたいだが
    cnt = 1
    sm = 0
    for i in range(n):#ここがwhileだったのを修正して減らした
        if sm <= mid-w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt>k:
        mn = mid
        mid = (mid+mx)//2
    else:
        mx = mid
        mid = (mid+mn)//2
#最終的な実行可能解が不明、結局最後mn,mid,mx全部チェックしてる
ans=[]
for a in [mn,mid,mx]:
    cnt = 1
    sm = 0
    for i in range(n):
        if sm <= a - w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt<=k:
        ans.append(a)
    else:
        pass

print(min(ans))
#最終的な実行可能解は(直前までmidだった)mx

