def check_load(k, w, max_weight) -> bool:
  truck_itr = 0
  truck_weight = 0
  for w_i in w:
    if w_i > max_weight:
      return False
    if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

    truck_weight += w_i
    if truck_itr > k-1:
      return False
    
  return True

def solve():
  # input
  n,k = map(int, input().split())
  w = []
  truck = []
  for i in range(1,n+1):
    w.append(int(input()))

  # kの積載量に対してトラックに詰めこむ操作の二分法で探索する。
  right = sum(w) # 解の上界
  left = sum(w)//n # 平均を床関数とったものが下界
  max_weight = left
  while right-left > 1:
    # print(left,right,max_weight)
    if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

    max_weight = (right+left)//2
  
  print(right)
  
solve() def check_load(k, w, max_weight) -> bool:
  truck_itr = 0
  truck_weight = 0
  for w_i in w:
    if w_i > max_weight:
      return False
    if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

    truck_weight += w_i
    if truck_itr > k-1:
      return False
    
  return True check_load truck_itr = 0 truck_itr 0 truck_weight = 0 truck_weight 0 for w_i in w:
    if w_i > max_weight:
      return False
    if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

    truck_weight += w_i
    if truck_itr > k-1:
      return False
    
   w_i w if w_i > max_weight:
      return False
     w_i > max_weight w_i max_weight return False False if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

     truck_weight + w_i > max_weight truck_weight + w_i truck_weight w_i max_weight truck_weight = 0 truck_weight 0 truck_itr += 1 truck_itr 1 truck_weight += w_i truck_weight w_i if truck_itr > k-1:
      return False
    
   truck_itr > k-1 truck_itr k-1 k 1 return False False return True True k k w w max_weight max_weight def solve():
  # input
  n,k = map(int, input().split())
  w = []
  truck = []
  for i in range(1,n+1):
    w.append(int(input()))

  # kの積載量に対してトラックに詰めこむ操作の二分法で探索する。
  right = sum(w) # 解の上界
  left = sum(w)//n # 平均を床関数とったものが下界
  max_weight = left
  while right-left > 1:
    # print(left,right,max_weight)
    if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

    max_weight = (right+left)//2
  
  print(right)
   solve n,k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w = [] w [] truck = [] truck [] for i in range(1,n+1):
    w.append(int(input()))

  # kの積載量に対してトラックに詰めこむ操作の二分法で探索する。
   i range(1,n+1) range 1 n+1 n 1 w.append(int(input())) w.append w append int(input()) int input() input right = sum(w) right sum(w) sum w left = sum(w)//n left sum(w)//n sum(w) sum w n max_weight = left max_weight left while right-left > 1:
    # print(left,right,max_weight)
    if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

    max_weight = (right+left)//2
  
   right-left > 1 right-left right left 1 if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

     check_load(k, w, max_weight) check_load k w max_weight right = max_weight right max_weight left = max_weight left max_weight max_weight = (right+left)//2 max_weight (right+left)//2 right+left right left 2 print(right) print right solve() solve def solve():
  # input
  n,k = map(int, input().split())
  w = []
  truck = []
  for i in range(1,n+1):
    w.append(int(input()))

  # kの積載量に対してトラックに詰めこむ操作の二分法で探索する。
  right = sum(w) # 解の上界
  left = sum(w)//n # 平均を床関数とったものが下界
  max_weight = left
  while right-left > 1:
    # print(left,right,max_weight)
    if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

    max_weight = (right+left)//2
  
  print(right)
   def solve():
  # input
  n,k = map(int, input().split())
  w = []
  truck = []
  for i in range(1,n+1):
    w.append(int(input()))

  # kの積載量に対してトラックに詰めこむ操作の二分法で探索する。
  right = sum(w) # 解の上界
  left = sum(w)//n # 平均を床関数とったものが下界
  max_weight = left
  while right-left > 1:
    # print(left,right,max_weight)
    if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

    max_weight = (right+left)//2
  
  print(right)
   solve def check_load(k, w, max_weight) -> bool:
  truck_itr = 0
  truck_weight = 0
  for w_i in w:
    if w_i > max_weight:
      return False
    if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

    truck_weight += w_i
    if truck_itr > k-1:
      return False
    
  return True def check_load(k, w, max_weight) -> bool:
  truck_itr = 0
  truck_weight = 0
  for w_i in w:
    if w_i > max_weight:
      return False
    if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

    truck_weight += w_i
    if truck_itr > k-1:
      return False
    
  return True check_load
def check_load(k, w, max_weight) -> bool:
  truck_itr = 0
  truck_weight = 0
  for w_i in w:
    if w_i > max_weight:
      return False
    if truck_weight + w_i > max_weight:
      truck_weight = 0
      truck_itr += 1

    truck_weight += w_i
    if truck_itr > k-1:
      return False
    
  return True

def solve():
  # input
  n,k = map(int, input().split())
  w = []
  truck = []
  for i in range(1,n+1):
    w.append(int(input()))

  # kの積載量に対してトラックに詰めこむ操作の二分法で探索する。
  right = sum(w) # 解の上界
  left = sum(w)//n # 平均を床関数とったものが下界
  max_weight = left
  while right-left > 1:
    # print(left,right,max_weight)
    if check_load(k, w, max_weight):
      right = max_weight
    else:
      left = max_weight

    max_weight = (right+left)//2
  
  print(right)
  
solve()
