n,k=map(int,input().split())

W=[int(input()) for _ in range(n)]

def Wcheck(W,P,k):
    i=0
    for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

    return i

def PSearch(W,start,end,k):
    if start==end:
        return start
    mid=(start+end)//2
    v=Wcheck(W,mid,k)
    if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k)

print(PSearch(W,0,1000000000,k)) 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 W=[int(input()) for _ in range(n)] W [int(input()) for _ in range(n)] def Wcheck(W,P,k):
    i=0
    for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

    return i Wcheck i=0 i 0 for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

     j range(k) range k temp_w=0 temp_w 0 while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

     temp_w+W[i]<=P temp_w+W[i] temp_w W[i] W i P temp_w=temp_w+W[i] temp_w temp_w+W[i] temp_w W[i] W i i=i+1 i i+1 i 1 if i==len(W):
                return len(W)

     i==len(W) i len(W) len W return len(W) len(W) len W return i i W W P P k k def PSearch(W,start,end,k):
    if start==end:
        return start
    mid=(start+end)//2
    v=Wcheck(W,mid,k)
    if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k) PSearch if start==end:
        return start
     start==end start end return start start mid=(start+end)//2 mid (start+end)//2 start+end start end 2 v=Wcheck(W,mid,k) v Wcheck(W,mid,k) Wcheck W mid k if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k) v>=n v n return PSearch(W,start,mid,k) PSearch(W,start,mid,k) PSearch W start mid k return PSearch(W,mid+1,end,k) PSearch(W,mid+1,end,k) PSearch W mid+1 mid 1 end k W W start start end end k k print(PSearch(W,0,1000000000,k)) print PSearch(W,0,1000000000,k) PSearch W 0 1000000000 k def PSearch(W,start,end,k):
    if start==end:
        return start
    mid=(start+end)//2
    v=Wcheck(W,mid,k)
    if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k) def PSearch(W,start,end,k):
    if start==end:
        return start
    mid=(start+end)//2
    v=Wcheck(W,mid,k)
    if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k) PSearch def Wcheck(W,P,k):
    i=0
    for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

    return i def Wcheck(W,P,k):
    i=0
    for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

    return i Wcheck n,k=map(int,input().split()) map(int,input().split()) n W=[int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W k=map(int,input().split()) map(int,input().split()) k
n,k=map(int,input().split())

W=[int(input()) for _ in range(n)]

def Wcheck(W,P,k):
    i=0
    for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

    return i

def PSearch(W,start,end,k):
    if start==end:
        return start
    mid=(start+end)//2
    v=Wcheck(W,mid,k)
    if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k)

print(PSearch(W,0,1000000000,k))
