
def check(P,k,staffList):
    i = 0
    for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
    return i


def getMaxP(n,k,staffList):
    # Pが増えれば，入れられる個数は単純増加するので，二部探索によりPの最小値を求められる
    left = 0
    right = 100000*10000
    while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            right = mid
        else:
            left = mid

    return right


if __name__ == "__main__":
    n,k = map(int,input().split())
    staffList = [int(input()) for _ in range(n)]

    # 特定の最大積載量でどれだけ積めるのかを計算する
    P = getMaxP(n,k,staffList)

    print(P) def check(P,k,staffList):
    i = 0
    for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
    return i check i = 0 i 0 for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
     _ range(k) range k staffNum = 0 staffNum 0 while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
     staffNum + staffList[i]<= P staffNum + staffList[i] staffNum staffList[i] staffList i P staffNum += staffList[i] staffNum staffList[i] staffList i i += 1 i 1 if i == n:
                return n
     i == n i n return n n return i i P P k k staffList staffList def getMaxP(n,k,staffList):
    # Pが増えれば，入れられる個数は単純増加するので，二部探索によりPの最小値を求められる
    left = 0
    right = 100000*10000
    while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            right = mid
        else:
            left = mid

    return right getMaxP left = 0 left 0 right = 100000*10000 right 100000*10000 100000 10000 while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            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 staffNum = check(mid,k,staffList) staffNum check(mid,k,staffList) check mid k staffList if staffNum >= n :
            right = mid
        else:
            left = mid

     staffNum >= n staffNum n right = mid right mid left = mid left mid return right right n n k k staffList staffList if __name__ == "__main__":
    n,k = map(int,input().split())
    staffList = [int(input()) for _ in range(n)]

    # 特定の最大積載量でどれだけ積めるのかを計算する
    P = getMaxP(n,k,staffList)

    print(P) __name__ == "__main__" __name__ "__main__" 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 staffList = [int(input()) for _ in range(n)] staffList [int(input()) for _ in range(n)] P = getMaxP(n,k,staffList) P getMaxP(n,k,staffList) getMaxP n k staffList print(P) print P P = getMaxP(n,k,staffList) getMaxP(n,k,staffList) P n,k = map(int,input().split()) map(int,input().split()) n def check(P,k,staffList):
    i = 0
    for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
    return i def check(P,k,staffList):
    i = 0
    for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
    return i check def getMaxP(n,k,staffList):
    # Pが増えれば，入れられる個数は単純増加するので，二部探索によりPの最小値を求められる
    left = 0
    right = 100000*10000
    while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            right = mid
        else:
            left = mid

    return right def getMaxP(n,k,staffList):
    # Pが増えれば，入れられる個数は単純増加するので，二部探索によりPの最小値を求められる
    left = 0
    right = 100000*10000
    while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            right = mid
        else:
            left = mid

    return right getMaxP k = map(int,input().split()) map(int,input().split()) k staffList = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] staffList

def check(P,k,staffList):
    i = 0
    for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
    return i


def getMaxP(n,k,staffList):
    # Pが増えれば，入れられる個数は単純増加するので，二部探索によりPの最小値を求められる
    left = 0
    right = 100000*10000
    while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            right = mid
        else:
            left = mid

    return right


if __name__ == "__main__":
    n,k = map(int,input().split())
    staffList = [int(input()) for _ in range(n)]

    # 特定の最大積載量でどれだけ積めるのかを計算する
    P = getMaxP(n,k,staffList)

    print(P)
