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 can_cant(n, k, w_n, p):
      w_p = []
      wp = 0
      for w in w_n:
          if w > p:
              return False
          elif wp + w < p:
              wp += w
          elif wp + w == p:
              wp += w
              w_p.append(wp)
              wp = 0
          elif wp + w > p:
              w_p.append(wp)
              wp = w
          # else:
          # if wp!=0:
          # w_p.append(wp)
          #  wp=0
          #   else:wp=w
  
      if wp < p:
          w_p.append(wp)
  
      if len(w_p) <= k:
          # print("True")
          return True
      elif len(w_p) > k:
          # print("False")
          return False
  
  
  if __name__ == "__main__":
  
      n, k = list(
          map(
              int,
              input(
                  "??????????????°??¨????????°??°?????\?????????:",
              ).split(),
          )
      )
  
      w_n = [
          int(
              input(
                  "????????????????????\?????????:",
              )
          )
          for i in range(n)
      ]
  
      # print(can_cant(n,k,w_n,10))
  
      min_p = sum(w_n) // k
      max_p = sum(w_n)
      p = (min_p + max_p) // 2
      # print("min_p={},max_p={},p={}".format(min_p, max_p, p))
      pre_p = 0
  
      while min_p < p:
          print(p)
          result = can_cant(n, k, w_n, p)
          if result:
              pre_p = p
              max_p = p
              p = (min_p + max_p) // 2
              # print("max_p=p={},min_p={}, p={}".format(max_p, min_p, p))
          elif not result:
              pre_p = p
              min_p = p
              p = (min_p + max_p) // 2
              # print("max_p={},min_p=p={}, p={}".format(max_p, min_p, p))
      print(pre_p)
  
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."}]