output_description: Print the minimum value of $P$ in a line.
input_description: In the first line, two integers $n$ and $k$ are given separated by a space
  character. In the following $n$ lines, $w_i$ are given respectively.
attempt: # coding:utf-8
  
  n, k = map(int, input().split())
  backList = []
  for i in range(n):
      backList.append(int(input()))
  
  
  def capa(p, k):
      cnt = 0
      pcopy = p
      num = 0
      for back in backList:
          if back > p:
              break
          if back <= pcopy:
              pcopy -= back
              cnt += 1
              continue
          elif back > pcopy:
              if num == k - 1:
                  return cnt
              pcopy = p - back
              cnt += 1
              num += 1
      return cnt
  
  
  p_min = 0
  p_max = 100000 * 10000
  
  
  def biSearch(p_min, p_max):
      p = p_max - p_min
      if p_max - p_min <= 1:
          return p_max
      if p % 2 == 0:
          c = p_min + int(p / 2)
      else:
          c = p_min + int((p + 1) / 2)
      v = capa(c, k)
      if v < n:
          p_min = c
      else:
          p_max = c
  
      return biSearch(p_min, p_max)
  
  
  p = biSearch(p_min, p_max)
  n_init = n
  while n_init <= n:
      p -= 1
      n = capa(p, k)
  
  print(p + 1)
  
problem_description: Input
  
  In the first line, two integers $n$ and $k$ are given separated by a space
  character. In the following $n$ lines, $w_i$ are given respectively.
samples: [{"input": "5 3\n    8\n    1\n    7\n    3\n    9", "output": "10\n    \n\nIf the first truck loads two packages of $\\\\{8, 1\\\\}$, the second truck loads\ntwo packages of $\\\\{7, 3\\\\}$ and the third truck loads a package of $\\\\{9\\\\}$,\nthen the minimum value of the maximum load $P$ shall be 10."}, {"input": "4 2\n    1\n    2\n    2\n    6", "output": "6\n    \n\nIf the first truck loads three packages of $\\\\{1, 2, 2\\\\}$ and the second\ntruck loads a package of $\\\\{6\\\\}$, then the minimum value of the maximum load\n$P$ shall be 6."}]