def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True

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

min_p = max(arr)
max_p = sum(arr)
while min_p < max_p:
  mid_p = (min_p + max_p) // 2
  if check(mid_p, k, arr):
    max_p = mid_p
  else:
    min_p = mid_p + 1

print(min_p) def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True check subtotal = 0 subtotal 0 num_of_tracks = 1 num_of_tracks 1 for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
   a arr subtotal += a subtotal a if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
   subtotal > p subtotal p num_of_tracks += 1 num_of_tracks 1 if num_of_tracks > k: return False
       num_of_tracks > k num_of_tracks k subtotal = a subtotal a return True True p p k k arr arr n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () 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 arr = [int(input()) for i in range(n)] arr [int(input()) for i in range(n)] min_p = max(arr) min_p max(arr) max arr max_p = sum(arr) max_p sum(arr) sum arr while min_p < max_p:
  mid_p = (min_p + max_p) // 2
  if check(mid_p, k, arr):
    max_p = mid_p
  else:
    min_p = mid_p + 1 min_p < max_p min_p max_p mid_p = (min_p + max_p) // 2 mid_p (min_p + max_p) // 2 min_p + max_p min_p max_p 2 if check(mid_p, k, arr):
    max_p = mid_p
  else:
    min_p = mid_p + 1 check(mid_p, k, arr) check mid_p k arr max_p = mid_p max_p mid_p min_p = mid_p + 1 min_p mid_p + 1 mid_p 1 print(min_p) print min_p arr = [int(input()) for i in range(n)] [int(input()) for i in range(n)] arr min_p = mid_p + 1 mid_p + 1 min_p def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True check max_p = mid_p mid_p max_p min_p = max(arr) max(arr) min_p max_p = sum(arr) sum(arr) max_p k = map(int, input().split()) map(int, input().split()) k mid_p = (min_p + max_p) // 2 (min_p + max_p) // 2 mid_p n, k = map(int, input().split()) map(int, input().split()) n
def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True

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

min_p = max(arr)
max_p = sum(arr)
while min_p < max_p:
  mid_p = (min_p + max_p) // 2
  if check(mid_p, k, arr):
    max_p = mid_p
  else:
    min_p = mid_p + 1

print(min_p)