#!/usr/bin/env python3
import sys,collections
n,k = map(int,sys.stdin.readline().split())
w = list(map(int,sys.stdin.readlines()))
ng = sum(w)//k-1
ok = sum(w)
def isOK(p):
  j = 0
  for i in range(k):
    s = 0
    while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
  return j == n
while ok - ng > 1:
  mid = (ok+ng)//2
  t = collections.Counter(w)
  if isOK(mid):
    ok = mid
  else:
    ng = mid
print(ok) import sys,collections sys collections n,k = map(int,sys.stdin.readline().split()) n map(int,sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split k w = list(map(int,sys.stdin.readlines())) w list(map(int,sys.stdin.readlines())) list map(int,sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines ng = sum(w)//k-1 ng sum(w)//k-1 sum(w)//k sum(w) sum w k 1 ok = sum(w) ok sum(w) sum w def isOK(p):
  j = 0
  for i in range(k):
    s = 0
    while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
  return j == n isOK j = 0 j 0 for i in range(k):
    s = 0
    while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
   i range(k) range k s = 0 s 0 while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
   j < n and s + w[j] <= p j < n j n s + w[j] <= p s + w[j] s w[j] w j p s += w[j] s w[j] w j j += 1 j 1 return j == n j == n j n p p while ok - ng > 1:
  mid = (ok+ng)//2
  t = collections.Counter(w)
  if isOK(mid):
    ok = mid
  else:
    ng = mid ok - ng > 1 ok - ng ok ng 1 mid = (ok+ng)//2 mid (ok+ng)//2 ok+ng ok ng 2 t = collections.Counter(w) t collections.Counter(w) collections.Counter collections Counter w if isOK(mid):
    ok = mid
  else:
    ng = mid isOK(mid) isOK mid ok = mid ok mid ng = mid ng mid print(ok) print ok w = list(map(int,sys.stdin.readlines())) list(map(int,sys.stdin.readlines())) w mid = (ok+ng)//2 (ok+ng)//2 mid t = collections.Counter(w) collections.Counter(w) t ok = mid mid ok n,k = map(int,sys.stdin.readline().split()) map(int,sys.stdin.readline().split()) n ng = sum(w)//k-1 sum(w)//k-1 ng def isOK(p):
  j = 0
  for i in range(k):
    s = 0
    while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
  return j == n def isOK(p):
  j = 0
  for i in range(k):
    s = 0
    while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
  return j == n isOK ok = sum(w) sum(w) ok ng = mid mid ng k = map(int,sys.stdin.readline().split()) map(int,sys.stdin.readline().split()) k
#!/usr/bin/env python3
import sys,collections
n,k = map(int,sys.stdin.readline().split())
w = list(map(int,sys.stdin.readlines()))
ng = sum(w)//k-1
ok = sum(w)
def isOK(p):
  j = 0
  for i in range(k):
    s = 0
    while j < n and s + w[j] <= p:
      s += w[j]
      j += 1
  return j == n
while ok - ng > 1:
  mid = (ok+ng)//2
  t = collections.Counter(w)
  if isOK(mid):
    ok = mid
  else:
    ng = mid
print(ok)
