def check(p):
    global k, wlist   
    loadage = 0
    num = 1
    
    for w in wlist:
        loadage += w
        if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
    return True

n, k = map(int, input().split())
wlist = []

for _ in range(n):
    wlist.append(int(input()))
    
maxw = max(wlist)
sumw = sum(wlist)
p = 0

while maxw < sumw:
    p = (maxw + sumw) // 2
    if check(p):
        sumw = p
    else:
        maxw = p = p+1
        
print(p) def check(p):
    global k, wlist   
    loadage = 0
    num = 1
    
    for w in wlist:
        loadage += w
        if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
    return True check global k, wlist loadage = 0 loadage 0 num = 1 num 1 for w in wlist:
        loadage += w
        if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
     w wlist loadage += w loadage w if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
     loadage > p loadage p num += 1 num 1 if num > k:
                return False
             num > k num k return False False loadage = w loadage w return True True p p n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k wlist = [] wlist [] for _ in range(n):
    wlist.append(int(input()))
     _ range(n) range n wlist.append(int(input())) wlist.append wlist append int(input()) int input() input maxw = max(wlist) maxw max(wlist) max wlist sumw = sum(wlist) sumw sum(wlist) sum wlist p = 0 p 0 while maxw < sumw:
    p = (maxw + sumw) // 2
    if check(p):
        sumw = p
    else:
        maxw = p = p+1
         maxw < sumw maxw sumw p = (maxw + sumw) // 2 p (maxw + sumw) // 2 maxw + sumw maxw sumw 2 if check(p):
        sumw = p
    else:
        maxw = p = p+1
         check(p) check p sumw = p sumw p maxw = p = p+1 maxw p+1 p 1 = p = p+1 p p+1 print(p) print p def check(p):
    global k, wlist   
    loadage = 0
    num = 1
    
    for w in wlist:
        loadage += w
        if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
    return True def check(p):
    global k, wlist   
    loadage = 0
    num = 1
    
    for w in wlist:
        loadage += w
        if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
    return True check wlist = [] [] wlist sumw = sum(wlist) sum(wlist) sumw sumw = p p sumw maxw = max(wlist) max(wlist) maxw n, k = map(int, input().split()) map(int, input().split()) n p = 0 0 p maxw = p = p+1 p+1 maxw p = p+1 p+1 p k = map(int, input().split()) map(int, input().split()) k p = (maxw + sumw) // 2 (maxw + sumw) // 2 p
def check(p):
    global k, wlist   
    loadage = 0
    num = 1
    
    for w in wlist:
        loadage += w
        if loadage > p:
            num += 1
            if num > k:
                return False
            loadage = w
    return True

n, k = map(int, input().split())
wlist = []

for _ in range(n):
    wlist.append(int(input()))
    
maxw = max(wlist)
sumw = sum(wlist)
p = 0

while maxw < sumw:
    p = (maxw + sumw) // 2
    if check(p):
        sumw = p
    else:
        maxw = p = p+1
        
print(p)
