import sys

n,k=list(map(int,input().split()))

w=list(map(int,sys.stdin.readlines()))

def f():

 i=0

 for _ in[0]*k:

  s=0

  while s+w[i]<=m:

   s+=w[i];i+=1

   if i==n:return n

 return i

l,r=max(w),sum(w)

while l<r:

 m=(l+r)//2

 if f()>=n:r=m

 else:l=m+1

print(r)

import sys

def s():

 n,k=list(map(int,input().split()))

 w=list(map(int,sys.stdin.readlines()))

 def f():

  c=t=0

  for j in w:

   t+=j

   if t>m:

    t=j

    c+=1

    if c>=k:return 0

  return 1

 l,r=max(w),sum(w)

 while l<r:

  m=(l+r)//2

  if f():r=m

  else:l=m+1

 print(r)

if'__main__'==__name__:s()

import sys

n, k = list(map(int, input().split()))
w = list(map(int, sys.stdin.readlines()))


def f():
    i = 0
    for _ in [0] * k:
        s = 0
        while s + w[i] <= m:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i


l, r = max(w), sum(w)
while l < r:
    m = (l + r) // 2
    if f() >= n:
        r = m
    else:
        l = m + 1
print(r)

import sys


def s():
    n, k = list(map(int, input().split()))
    w = list(map(int, sys.stdin.readlines()))

    def f():
        c = t = 0
        for j in w:
            t += j
            if t > m:
                t = j
                c += 1
                if c >= k:
                    return 0
        return 1

    l, r = max(w), sum(w)
    while l < r:
        m = (l + r) // 2
        if f():
            r = m
        else:
            l = m + 1
    print(r)


if "__main__" == __name__:
    s()

-n, k = list(map(int, input().split())) -w = list(map(int, sys.stdin.readlines())) + +def s(): +    n, k = list(map(int, input().split())) +    w = list(map(int, sys.stdin.readlines())) + +    def f(): +        c = t = 0 +        for j in w: +            t += j +            if t > m: +                t = j +                c += 1 +                if c >= k: +                    return 0 +        return 1 + +    l, r = max(w), sum(w) +    while l < r: +        m = (l + r) // 2 +        if f(): +            r = m +        else: +            l = m + 1 +    print(r) -def f(): -    i = 0 -    for _ in [0] * k: -        s = 0 -        while s + w[i] <= m: -            s += w[i] -            i += 1 -            if i == n: -                return n -    return i - - -l, r = max(w), sum(w) -while l < r: -    m = (l + r) // 2 -    if f() >= n: -        r = m -    else: -        l = m + 1 -print(r) +if "__main__" == __name__: +    s()