from collections import deque

nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])
w = []
for i in range(0, n):
  w.append(int(input()))

# 1台あたりの積載量がvのとき、荷物の配列aを積めるか返す
def allocatable(a, v):
  b = deque(a)
  currentCar = 0
  wSum = 0
  while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
  return not b

# 最小の積載量Pを求める
def search(a):
  l = 0
  r = 1000000000
  while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
  return r

print(search(w)) from collections import deque nk = input().split(' ') nk input().split(' ') ().split () input split ' ' n = int(nk[0]) n int(nk[0]) int nk[0] nk 0 k = int(nk[1]) k int(nk[1]) int nk[1] nk 1 w = [] w [] for i in range(0, n):
  w.append(int(input()))

# 1台あたりの積載量がvのとき、荷物の配列aを積めるか返す i range(0, n) range 0 n w.append(int(input())) w.append w append int(input()) int input() input def allocatable(a, v):
  b = deque(a)
  currentCar = 0
  wSum = 0
  while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
  return not b

# 最小の積載量Pを求める allocatable b = deque(a) b deque(a) deque a currentCar = 0 currentCar 0 wSum = 0 wSum 0 while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
   currentCar < k currentCar k weight = b.popleft() weight b.popleft() b.popleft b popleft if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
     wSum + weight <= v wSum + weight wSum weight v wSum += weight wSum weight b.appendleft(weight) b.appendleft b appendleft weight currentCar += 1 currentCar 1 wSum = 0 wSum 0 if not b:
      return True
  # 最後の車まで来て残っていればFalse
   not b b return True True return not b not b b a a v v def search(a):
  l = 0
  r = 1000000000
  while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
  return r search l = 0 l 0 r = 1000000000 r 1000000000 while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
   l + 1 < r l + 1 l 1 r i = int((l + r) / 2) i int((l + r) / 2) int (l + r) / 2 l + r l r 2 if allocatable(a, i):
      r = i
    else:
      l = i
   allocatable(a, i) allocatable a i r = i r i l = i l i return r r a a print(search(w)) print search(w) search w def search(a):
  l = 0
  r = 1000000000
  while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
  return r def search(a):
  l = 0
  r = 1000000000
  while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
  return r search w = [] [] w def allocatable(a, v):
  b = deque(a)
  currentCar = 0
  wSum = 0
  while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
  return not b

# 最小の積載量Pを求める def allocatable(a, v):
  b = deque(a)
  currentCar = 0
  wSum = 0
  while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
  return not b

# 最小の積載量Pを求める allocatable nk = input().split(' ') input().split(' ') nk n = int(nk[0]) int(nk[0]) n k = int(nk[1]) int(nk[1]) k
from collections import deque

nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])
w = []
for i in range(0, n):
  w.append(int(input()))

# 1台あたりの積載量がvのとき、荷物の配列aを積めるか返す
def allocatable(a, v):
  b = deque(a)
  currentCar = 0
  wSum = 0
  while currentCar < k:
    weight = b.popleft()
    if wSum + weight <= v:
      wSum += weight
    else:
      # 積み切れなければbに戻して次の車へ
      b.appendleft(weight)
      currentCar += 1
      wSum = 0
    # bに要素が残っていなければ積み切った => True
    if not b:
      return True
  # 最後の車まで来て残っていればFalse
  return not b

# 最小の積載量Pを求める
def search(a):
  l = 0
  r = 1000000000
  while l + 1 < r:
    i = int((l + r) / 2)
    if allocatable(a, i):
      r = i
    else:
      l = i
  return r

print(search(w))
