n, k = map(int, input().split())
pack = []
for i in range(n):
    pack.append(int(input()))

def trucks(p, k):
    t = 0
    c = 1
    for i in range(len(p)):
        if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
    return c

minp = int(sum(pack) / k)
maxp = max(pack) * n
while minp < maxp - 1:
    p = int((maxp + minp) / 2)
    if trucks(pack, p) <= k:
        maxp = p
    else:
        minp = p

if trucks(pack, maxp - 1) <= k:
    print(maxp - 1)
else:
    print(maxp) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k pack = [] pack [] for i in range(n):
    pack.append(int(input())) i range(n) range n pack.append(int(input())) pack.append pack append int(input()) int input() input def trucks(p, k):
    t = 0
    c = 1
    for i in range(len(p)):
        if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
    return c trucks t = 0 t 0 c = 1 c 1 for i in range(len(p)):
        if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
     i range(len(p)) range len(p) len p if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
     p[i] > k p[i] p i k return 1000000 1000000 elif t + p[i] <= k:
            t += p[i]
         t + p[i] <= k t + p[i] t p[i] p i k t += p[i] t p[i] p i t = p[i] t p[i] p i c += 1 c 1 return c c p p k k minp = int(sum(pack) / k) minp int(sum(pack) / k) int sum(pack) / k sum(pack) sum pack k maxp = max(pack) * n maxp max(pack) * n max(pack) max pack n while minp < maxp - 1:
    p = int((maxp + minp) / 2)
    if trucks(pack, p) <= k:
        maxp = p
    else:
        minp = p minp < maxp - 1 minp maxp - 1 maxp 1 p = int((maxp + minp) / 2) p int((maxp + minp) / 2) int (maxp + minp) / 2 maxp + minp maxp minp 2 if trucks(pack, p) <= k:
        maxp = p
    else:
        minp = p trucks(pack, p) <= k trucks(pack, p) trucks pack p k maxp = p maxp p minp = p minp p if trucks(pack, maxp - 1) <= k:
    print(maxp - 1)
else:
    print(maxp) trucks(pack, maxp - 1) <= k trucks(pack, maxp - 1) trucks pack maxp - 1 maxp 1 k print(maxp - 1) print maxp - 1 maxp 1 print(maxp) print maxp minp = p p minp def trucks(p, k):
    t = 0
    c = 1
    for i in range(len(p)):
        if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
    return c def trucks(p, k):
    t = 0
    c = 1
    for i in range(len(p)):
        if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
    return c trucks maxp = p p maxp pack = [] [] pack p = int((maxp + minp) / 2) int((maxp + minp) / 2) p n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k minp = int(sum(pack) / k) int(sum(pack) / k) minp maxp = max(pack) * n max(pack) * n maxp
n, k = map(int, input().split())
pack = []
for i in range(n):
    pack.append(int(input()))

def trucks(p, k):
    t = 0
    c = 1
    for i in range(len(p)):
        if p[i] > k:
            return 1000000
        elif t + p[i] <= k:
            t += p[i]
        else:
            t = p[i]
            c += 1
    return c

minp = int(sum(pack) / k)
maxp = max(pack) * n
while minp < maxp - 1:
    p = int((maxp + minp) / 2)
    if trucks(pack, p) <= k:
        maxp = p
    else:
        minp = p

if trucks(pack, maxp - 1) <= k:
    print(maxp - 1)
else:
    print(maxp)
