n, k = [int(t) for t in input().split()]
w = [int(input()) for i in range(n)]

hi = sum(w)
lo = max(w)

def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True

P = hi
while lo < hi:
    m = (lo + hi) // 2
    if canMove(w, m, k):
        P = m
        hi = m
    else:
        lo = m + 1

print(P)
 int(t) for t in input().split() for t in input().split() t input().split() ().split () input split for t in input().split() int(t) int t n, k = [int(t) for t in input().split()] n [int(t) for t in input().split()] k int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input w = [int(input()) for i in range(n)] w [int(input()) for i in range(n)] hi = sum(w) hi sum(w) sum w lo = max(w) lo max(w) max w def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True canMove s = 0 s 0 for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
     i range(len(w)) range len(w) len w if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
         s + w[i] > P s + w[i] s w[i] w i P s = 0 s 0 k -= 1 k 1 if k <= 0: return False
         k <= 0 k 0 s += w[i] s w[i] w i return True True w w P P k k P = hi P hi while lo < hi:
    m = (lo + hi) // 2
    if canMove(w, m, k):
        P = m
        hi = m
    else:
        lo = m + 1 lo < hi lo hi m = (lo + hi) // 2 m (lo + hi) // 2 lo + hi lo hi 2 if canMove(w, m, k):
        P = m
        hi = m
    else:
        lo = m + 1 canMove(w, m, k) canMove w m k P = m P m hi = m hi m lo = m + 1 lo m + 1 m 1 print(P) print P hi = m m hi k = [int(t) for t in input().split()] [int(t) for t in input().split()] k P = m m P w = [int(input()) for i in range(n)] [int(input()) for i in range(n)] w m = (lo + hi) // 2 (lo + hi) // 2 m n, k = [int(t) for t in input().split()] [int(t) for t in input().split()] n hi = sum(w) sum(w) hi lo = max(w) max(w) lo P = hi hi P lo = m + 1 m + 1 lo def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True canMove
n, k = [int(t) for t in input().split()]
w = [int(input()) for i in range(n)]

hi = sum(w)
lo = max(w)

def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True

P = hi
while lo < hi:
    m = (lo + hi) // 2
    if canMove(w, m, k):
        P = m
        hi = m
    else:
        lo = m + 1

print(P)

