count = 0
$n = $k = 0
$w = []
STDIN.each_line {|line|
  if count == 0
    count = 1
    n_k = line.split " "
    $n = n_k[0].to_i
    $k = n_k[1].to_i
    next
  end

  $w << line.to_i
}

def is_allocatable value, k
  tmp_value = value
  alloc_count = 0
  l = 0
  r = $w.length
  while (l  + 1 < r)
    alloc_count += 1
    i = (r + l) / 2
    if $w[i] <= tmp_value
      l = i
      tmp_value -= $w[i]
    else
      tmp_value = value - $w[i]
      r = i
    end
  end

  return alloc_count
end

tmp = $w.inject(:+) / $k + 1

while (result = is_allocatable tmp, $k) != $k
  if result < $k
    tmp += 1
  else
    tmp -= 1
  end
end

puts tmp

