n,k=map(int,input().split())
w=[0]*n
for i in range(n):
    w[i] = int(input())

def hantei(w,a,k):
    tumu=a
    daime=1
    for ww in w:
        if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
    if daime >k:
        return False
    else:
        return True


right= max(w)*n +1
left = min(w)

while left<right:
    mid  = (left+right)//2
    if hantei(w,mid,k):
        right=mid
    else:
        left=mid+1
print(left)
 n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w=[0]*n w [0]*n [0] 0 n for i in range(n):
    w[i] = int(input()) i range(n) range n w[i] = int(input()) w[i] w i int(input()) int input() input def hantei(w,a,k):
    tumu=a
    daime=1
    for ww in w:
        if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
    if daime >k:
        return False
    else:
        return True hantei tumu=a tumu a daime=1 daime 1 for ww in w:
        if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
     ww w if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
     ww<=tumu ww tumu tumu-=ww tumu ww tumu=a tumu a daime+=1 daime 1 if ww<=tumu:
                tumu-=ww
            else:
                return False
     ww<=tumu ww tumu tumu-=ww tumu ww return False False if daime >k:
        return False
    else:
        return True daime >k daime k return False False return True True w w a a k k right= max(w)*n +1 right max(w)*n +1 max(w)*n max(w) max w n 1 left = min(w) left min(w) min w while left<right:
    mid  = (left+right)//2
    if hantei(w,mid,k):
        right=mid
    else:
        left=mid+1 left<right left right mid  = (left+right)//2 mid (left+right)//2 left+right left right 2 if hantei(w,mid,k):
        right=mid
    else:
        left=mid+1 hantei(w,mid,k) hantei w mid k right=mid right mid left=mid+1 left mid+1 mid 1 print(left) print left w=[0]*n [0]*n w def hantei(w,a,k):
    tumu=a
    daime=1
    for ww in w:
        if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
    if daime >k:
        return False
    else:
        return True def hantei(w,a,k):
    tumu=a
    daime=1
    for ww in w:
        if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
    if daime >k:
        return False
    else:
        return True hantei k=map(int,input().split()) map(int,input().split()) k n,k=map(int,input().split()) map(int,input().split()) n right=mid mid right left = min(w) min(w) left left=mid+1 mid+1 left right= max(w)*n +1 max(w)*n +1 right mid  = (left+right)//2 (left+right)//2 mid
n,k=map(int,input().split())
w=[0]*n
for i in range(n):
    w[i] = int(input())

def hantei(w,a,k):
    tumu=a
    daime=1
    for ww in w:
        if ww<=tumu:
            tumu-=ww
        else:        
            tumu=a
            daime+=1
            if ww<=tumu:
                tumu-=ww
            else:
                return False
    if daime >k:
        return False
    else:
        return True


right= max(w)*n +1
left = min(w)

while left<right:
    mid  = (left+right)//2
    if hantei(w,mid,k):
        right=mid
    else:
        left=mid+1
print(left)

