n, k = map(int, input().split())
wList = []
for i in range(n):
    w = int(input())
    wList.append(w)
minP = max(wList)-1
maxP = sum(wList)
def countD(mid, wList):
    curr = 0
    count = 0
    for w in wList:
        if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
    if curr > 0:
        count+=1
    return count
while maxP - minP > 1:
    mid = (minP + maxP)//2
    days = countD(mid, wList)
    if days <= k:
        maxP = mid
    else:
        minP = mid
print(maxP) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k wList = [] wList [] for i in range(n):
    w = int(input())
    wList.append(w) i range(n) range n w = int(input()) w int(input()) int input() input wList.append(w) wList.append wList append w minP = max(wList)-1 minP max(wList)-1 max(wList) max wList 1 maxP = sum(wList) maxP sum(wList) sum wList def countD(mid, wList):
    curr = 0
    count = 0
    for w in wList:
        if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
    if curr > 0:
        count+=1
    return count countD curr = 0 curr 0 count = 0 count 0 for w in wList:
        if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
     w wList if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
     curr+w > mid curr+w curr w mid count+=1 count 1 curr = w curr w curr+=w curr w if curr > 0:
        count+=1
     curr > 0 curr 0 count+=1 count 1 return count count mid mid wList wList while maxP - minP > 1:
    mid = (minP + maxP)//2
    days = countD(mid, wList)
    if days <= k:
        maxP = mid
    else:
        minP = mid maxP - minP > 1 maxP - minP maxP minP 1 mid = (minP + maxP)//2 mid (minP + maxP)//2 minP + maxP minP maxP 2 days = countD(mid, wList) days countD(mid, wList) countD mid wList if days <= k:
        maxP = mid
    else:
        minP = mid days <= k days k maxP = mid maxP mid minP = mid minP mid print(maxP) print maxP n, k = map(int, input().split()) map(int, input().split()) n maxP = mid mid maxP k = map(int, input().split()) map(int, input().split()) k wList = [] [] wList w = int(input()) int(input()) w minP = max(wList)-1 max(wList)-1 minP days = countD(mid, wList) countD(mid, wList) days def countD(mid, wList):
    curr = 0
    count = 0
    for w in wList:
        if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
    if curr > 0:
        count+=1
    return count def countD(mid, wList):
    curr = 0
    count = 0
    for w in wList:
        if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
    if curr > 0:
        count+=1
    return count countD mid = (minP + maxP)//2 (minP + maxP)//2 mid minP = mid mid minP maxP = sum(wList) sum(wList) maxP
n, k = map(int, input().split())
wList = []
for i in range(n):
    w = int(input())
    wList.append(w)
minP = max(wList)-1
maxP = sum(wList)
def countD(mid, wList):
    curr = 0
    count = 0
    for w in wList:
        if curr+w > mid:
            count+=1
            curr = w
        else:
            curr+=w
    if curr > 0:
        count+=1
    return count
while maxP - minP > 1:
    mid = (minP + maxP)//2
    days = countD(mid, wList)
    if days <= k:
        maxP = mid
    else:
        minP = mid
print(maxP)
