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: def judge(
      loads, truck, truck_weight
  ):  # loadsは荷物のリスト.truckは使えるトラックの台数
      truck_num = 1
      weight_sum = 0
      for load in loads:
          if weight_sum + load > truck_weight:
              truck_num += 1
              if truck < truck_num:
                  return 0
              weight_sum = load
          else:
              weight_sum += load
      return 1
  
  
  # 与えられた条件で荷物の積み込みが可能なら１、不可能なら０を返す
  
  
  def binal_search(
      loads, truck, min, max
  ):  # minからmaxの範囲で最小トラック積載量を求める
      if max == min:
          return min
      mid = (min + max) // 2
      if judge(loads, truck, mid):
          return binal_search(loads, truck, min, mid)
      else:
          return binal_search(loads, truck, mid + 1, max)
  
  
  n, truck = map(int, input().split())
  loads = []
  for loop in range(n):
      loads.append(int(input()))
  loads_max = sum(loads)
  loads_min = max(loads)
  print(binal_search(loads, truck, loads_min, loads_max))
  
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."}]