def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True

if __name__=='__main__':
    n,k = list(map(int, input().split()))
    W = list(map(int,[input() for _ in range(n)]))
    Pmax = sum(W)
    Pmin = 0
    while Pmin < Pmax:
        P = (Pmax + Pmin) // 2
        if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
    print(Pmax) def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True checkCapacity ws = 0 ws 0 cnt = 1 cnt 1 for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
     wi W if wi > P: return False
         wi > P wi P ws += wi ws wi if ws > P:
            cnt += 1
            ws = wi
         ws > P ws P cnt += 1 cnt 1 ws = wi ws wi if cnt > k: return False
     cnt > k cnt k return True True W W k k P P if __name__=='__main__':
    n,k = list(map(int, input().split()))
    W = list(map(int,[input() for _ in range(n)]))
    Pmax = sum(W)
    Pmin = 0
    while Pmin < Pmax:
        P = (Pmax + Pmin) // 2
        if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
    print(Pmax) __name__=='__main__' __name__ '__main__' n,k = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k input() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) input() input W = list(map(int,[input() for _ in range(n)])) W list(map(int,[input() for _ in range(n)])) list map(int,[input() for _ in range(n)]) map int [input() for _ in range(n)] Pmax = sum(W) Pmax sum(W) sum W Pmin = 0 Pmin 0 while Pmin < Pmax:
        P = (Pmax + Pmin) // 2
        if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
     Pmin < Pmax Pmin Pmax P = (Pmax + Pmin) // 2 P (Pmax + Pmin) // 2 Pmax + Pmin Pmax Pmin 2 if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
     checkCapacity(W,k,P) checkCapacity W k P Pmax = P Pmax P Pmin = P + 1 Pmin P + 1 P 1 print(Pmax) print Pmax n,k = list(map(int, input().split())) list(map(int, input().split())) n P = (Pmax + Pmin) // 2 (Pmax + Pmin) // 2 P k = list(map(int, input().split())) list(map(int, input().split())) k W = list(map(int,[input() for _ in range(n)])) list(map(int,[input() for _ in range(n)])) W def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True checkCapacity Pmax = sum(W) sum(W) Pmax Pmin = P + 1 P + 1 Pmin Pmin = 0 0 Pmin Pmax = P P Pmax
def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True

if __name__=='__main__':
    n,k = list(map(int, input().split()))
    W = list(map(int,[input() for _ in range(n)]))
    Pmax = sum(W)
    Pmin = 0
    while Pmin < Pmax:
        P = (Pmax + Pmin) // 2
        if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
    print(Pmax)