def canLoad(n, k, p):
    global w
    load = 0
    for i in range(n):
        load += w[i]
        if load <= p:
            continue
        k -= 1
        if k == 0:
            return False
        load = w[i]
    return True

def solve(n, k, pmin, pmax):
    if pmin + 1 >= pmax:
        return pmax
    newp = (pmax + pmin) // 2
    if canLoad(n, k, newp):
        return solve(n, k, pmin, newp)
    else:
        return solve(n, k, newp, pmax)

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

# p の最小の候補は wmax と ceil(wsum/k) の最大値
pmin = max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1)
pmax = wsum
p = pmin
if not canLoad(n, k, pmin):
    p = solve(n, k, pmin, pmax)
print(p)
 def canLoad(n, k, p):
    global w
    load = 0
    for i in range(n):
        load += w[i]
        if load <= p:
            continue
        k -= 1
        if k == 0:
            return False
        load = w[i]
    return True canLoad global w load = 0 load 0 for i in range(n):
        load += w[i]
        if load <= p:
            continue
        k -= 1
        if k == 0:
            return False
        load = w[i]
     i range(n) range n load += w[i] load w[i] w i if load <= p:
            continue
         load <= p load p continue k -= 1 k 1 if k == 0:
            return False
         k == 0 k 0 return False False load = w[i] load w[i] w i return True True n n k k p p def solve(n, k, pmin, pmax):
    if pmin + 1 >= pmax:
        return pmax
    newp = (pmax + pmin) // 2
    if canLoad(n, k, newp):
        return solve(n, k, pmin, newp)
    else:
        return solve(n, k, newp, pmax) solve if pmin + 1 >= pmax:
        return pmax
     pmin + 1 >= pmax pmin + 1 pmin 1 pmax return pmax pmax newp = (pmax + pmin) // 2 newp (pmax + pmin) // 2 pmax + pmin pmax pmin 2 if canLoad(n, k, newp):
        return solve(n, k, pmin, newp)
    else:
        return solve(n, k, newp, pmax) canLoad(n, k, newp) canLoad n k newp return solve(n, k, pmin, newp) solve(n, k, pmin, newp) solve n k pmin newp return solve(n, k, newp, pmax) solve(n, k, newp, pmax) solve n k newp pmax n n k k pmin pmin pmax pmax 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 wsum = 0 wsum 0 wmax = 0 wmax 0 for i in range(n):
    w[i] = int(input())
    wsum += w[i]
    if w[i] > wmax:
        wmax = w[i]

# p の最小の候補は wmax と ceil(wsum/k) の最大値 i range(n) range n w[i] = int(input()) w[i] w i int(input()) int input() input wsum += w[i] wsum w[i] w i if w[i] > wmax:
        wmax = w[i]

# p の最小の候補は wmax と ceil(wsum/k) の最大値 w[i] > wmax w[i] w i wmax wmax = w[i] wmax w[i] w i pmin = max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1) pmin max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1) max wmax wsum // k if wsum % k == 0 else wsum // k + 1 wsum % k == 0 wsum % k wsum k 0 wsum // k wsum k wsum // k + 1 wsum // k wsum k 1 pmax = wsum pmax wsum p = pmin p pmin if not canLoad(n, k, pmin):
    p = solve(n, k, pmin, pmax) not canLoad(n, k, pmin) canLoad(n, k, pmin) canLoad n k pmin p = solve(n, k, pmin, pmax) p solve(n, k, pmin, pmax) solve n k pmin pmax print(p) print p w = [0]*n [0]*n w pmin = max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1) max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1) pmin def canLoad(n, k, p):
    global w
    load = 0
    for i in range(n):
        load += w[i]
        if load <= p:
            continue
        k -= 1
        if k == 0:
            return False
        load = w[i]
    return True def canLoad(n, k, p):
    global w
    load = 0
    for i in range(n):
        load += w[i]
        if load <= p:
            continue
        k -= 1
        if k == 0:
            return False
        load = w[i]
    return True canLoad pmax = wsum wsum pmax p = solve(n, k, pmin, pmax) solve(n, k, pmin, pmax) p k = map(int, input().split()) map(int, input().split()) k def solve(n, k, pmin, pmax):
    if pmin + 1 >= pmax:
        return pmax
    newp = (pmax + pmin) // 2
    if canLoad(n, k, newp):
        return solve(n, k, pmin, newp)
    else:
        return solve(n, k, newp, pmax) def solve(n, k, pmin, pmax):
    if pmin + 1 >= pmax:
        return pmax
    newp = (pmax + pmin) // 2
    if canLoad(n, k, newp):
        return solve(n, k, pmin, newp)
    else:
        return solve(n, k, newp, pmax) solve wmax = w[i] w[i] wmax wmax = 0 0 wmax p = pmin pmin p wsum += w[i] w[i] wsum n, k = map(int, input().split()) map(int, input().split()) n wsum = 0 0 wsum
def canLoad(n, k, p):
    global w
    load = 0
    for i in range(n):
        load += w[i]
        if load <= p:
            continue
        k -= 1
        if k == 0:
            return False
        load = w[i]
    return True

def solve(n, k, pmin, pmax):
    if pmin + 1 >= pmax:
        return pmax
    newp = (pmax + pmin) // 2
    if canLoad(n, k, newp):
        return solve(n, k, pmin, newp)
    else:
        return solve(n, k, newp, pmax)

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

# p の最小の候補は wmax と ceil(wsum/k) の最大値
pmin = max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1)
pmax = wsum
p = pmin
if not canLoad(n, k, pmin):
    p = solve(n, k, pmin, pmax)
print(p)

