N, K = map(int, input().split())
W = []
for _ in range(N):
  W.append(int(input()))
    
def carriable(p):
  if p < max(W):
    return False
  
  k_count = 0
  current_weight = 0
  for w in W:
    if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
  return True

def solve():
  min_p = 0
  max_p = sum(W)
  current_p = (max_p + min_p) // 2
  
  while True:    
    if min_p == current_p:
      return max_p
    
    if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
    current_p = (max_p + min_p) // 2
    
print(solve()) N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K W = [] W [] for _ in range(N):
  W.append(int(input()))
     _ range(N) range N W.append(int(input())) W.append W append int(input()) int input() input def carriable(p):
  if p < max(W):
    return False
  
  k_count = 0
  current_weight = 0
  for w in W:
    if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
  return True carriable if p < max(W):
    return False
  
   p < max(W) p max(W) max W return False False k_count = 0 k_count 0 current_weight = 0 current_weight 0 for w in W:
    if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
   w W if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
   current_weight + w <= p current_weight + w current_weight w p current_weight += w current_weight w if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
   k_count + 1 < K k_count + 1 k_count 1 K k_count += 1 k_count 1 current_weight = w current_weight w return False False return True True p p def solve():
  min_p = 0
  max_p = sum(W)
  current_p = (max_p + min_p) // 2
  
  while True:    
    if min_p == current_p:
      return max_p
    
    if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
    current_p = (max_p + min_p) // 2
     solve min_p = 0 min_p 0 max_p = sum(W) max_p sum(W) sum W current_p = (max_p + min_p) // 2 current_p (max_p + min_p) // 2 max_p + min_p max_p min_p 2 while True:    
    if min_p == current_p:
      return max_p
    
    if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
    current_p = (max_p + min_p) // 2
     True if min_p == current_p:
      return max_p
    
     min_p == current_p min_p current_p return max_p max_p if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
     carriable(current_p) carriable current_p max_p = current_p max_p current_p min_p = current_p min_p current_p current_p = (max_p + min_p) // 2 current_p (max_p + min_p) // 2 max_p + min_p max_p min_p 2 print(solve()) print solve() solve K = map(int, input().split()) map(int, input().split()) K def carriable(p):
  if p < max(W):
    return False
  
  k_count = 0
  current_weight = 0
  for w in W:
    if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
  return True def carriable(p):
  if p < max(W):
    return False
  
  k_count = 0
  current_weight = 0
  for w in W:
    if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
  return True carriable N, K = map(int, input().split()) map(int, input().split()) N W = [] [] W def solve():
  min_p = 0
  max_p = sum(W)
  current_p = (max_p + min_p) // 2
  
  while True:    
    if min_p == current_p:
      return max_p
    
    if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
    current_p = (max_p + min_p) // 2
     def solve():
  min_p = 0
  max_p = sum(W)
  current_p = (max_p + min_p) // 2
  
  while True:    
    if min_p == current_p:
      return max_p
    
    if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
    current_p = (max_p + min_p) // 2
     solve
N, K = map(int, input().split())
W = []
for _ in range(N):
  W.append(int(input()))
    
def carriable(p):
  if p < max(W):
    return False
  
  k_count = 0
  current_weight = 0
  for w in W:
    if current_weight + w <= p:
      current_weight += w
    else:
      if k_count + 1 < K:
        k_count += 1
        current_weight = w
      else:
        return False
      
  return True

def solve():
  min_p = 0
  max_p = sum(W)
  current_p = (max_p + min_p) // 2
  
  while True:    
    if min_p == current_p:
      return max_p
    
    if carriable(current_p):
      max_p = current_p
    else:
      min_p = current_p
    current_p = (max_p + min_p) // 2
    
print(solve())
