n, k  = map(int, input().split())
w = []
def check(ptest):
    tk=1
    p=0
    global k
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>k:
            return 0
            #break   
    
    return 1
for i in range(n):
    w.append(int(input()))
pmax = sum(w)
pmin = pmax//k - 1


while (pmax - pmin) > 1:
    pmid = (pmax + pmin)//2
    if check(pmid) == 1:
        pmax = pmid
    else:
        pmin = pmid
print(pmax) n, k  = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w = [] w [] def check(ptest):
    tk=1
    p=0
    global k
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>k:
            return 0
            #break   
    
    return 1 check tk=1 tk 1 p=0 p 0 global k global w global n i=0 i 0 while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>k:
            return 0
            #break   
    
     i<n i n p+=w[i] p w[i] w i if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
         p<=ptest p ptest i+=1 i 1 tk+=1 tk 1 p=0 p 0 if tk>k:
            return 0
            #break   
    
     tk>k tk k return 0 0 return 1 1 ptest ptest for i in range(n):
    w.append(int(input())) i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input pmax = sum(w) pmax sum(w) sum w pmin = pmax//k - 1 pmin pmax//k - 1 pmax//k pmax k 1 while (pmax - pmin) > 1:
    pmid = (pmax + pmin)//2
    if check(pmid) == 1:
        pmax = pmid
    else:
        pmin = pmid (pmax - pmin) > 1 pmax - pmin pmax pmin 1 pmid = (pmax + pmin)//2 pmid (pmax + pmin)//2 pmax + pmin pmax pmin 2 if check(pmid) == 1:
        pmax = pmid
    else:
        pmin = pmid check(pmid) == 1 check(pmid) check pmid 1 pmax = pmid pmax pmid pmin = pmid pmin pmid print(pmax) print pmax n, k  = map(int, input().split()) map(int, input().split()) n k  = map(int, input().split()) map(int, input().split()) k w = [] [] w pmax = sum(w) sum(w) pmax pmax = pmid pmid pmax def check(ptest):
    tk=1
    p=0
    global k
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>k:
            return 0
            #break   
    
    return 1 def check(ptest):
    tk=1
    p=0
    global k
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>k:
            return 0
            #break   
    
    return 1 check pmin = pmid pmid pmin pmin = pmax//k - 1 pmax//k - 1 pmin pmid = (pmax + pmin)//2 (pmax + pmin)//2 pmid
n, k  = map(int, input().split())
w = []
def check(ptest):
    tk=1
    p=0
    global k
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>k:
            return 0
            #break   
    
    return 1
for i in range(n):
    w.append(int(input()))
pmax = sum(w)
pmin = pmax//k - 1


while (pmax - pmin) > 1:
    pmid = (pmax + pmin)//2
    if check(pmid) == 1:
        pmax = pmid
    else:
        pmin = pmid
print(pmax)
