# -*- coding: utf-8 -*-
import sys
from sys import stdin
import math

n, k = map(int, stdin.readline().split())
w = list([int(stdin.readline().rstrip()) for i in range(n)])

def main2():
  def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

  r = sum(w)
  l = max(math.ceil(r/k),max(w))
  while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
  print(r)

if __name__ == '__main__':
  main2()
 import sys sys from sys import stdin import math math n, k = map(int, stdin.readline().split()) n map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split k int(stdin.readline().rstrip()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(stdin.readline().rstrip()) int stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip w = list([int(stdin.readline().rstrip()) for i in range(n)]) w list([int(stdin.readline().rstrip()) for i in range(n)]) list [int(stdin.readline().rstrip()) for i in range(n)] def main2():
  def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

  r = sum(w)
  l = max(math.ceil(r/k),max(w))
  while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
  print(r) main2 def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

   is_ok cnt_track = w_tmp = 0 cnt_track 0 = w_tmp = 0 w_tmp 0 for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
     w_i w w_tmp += w_i w_tmp w_i if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
     w_tmp > m w_tmp m w_tmp = w_i w_tmp w_i cnt_track += 1 cnt_track 1 if cnt_track >= k:
          return 0
     cnt_track >= k cnt_track k return 0 0 return 1 1 r = sum(w) r sum(w) sum w l = max(math.ceil(r/k),max(w)) l max(math.ceil(r/k),max(w)) max math.ceil(r/k) math.ceil math ceil r/k r k max(w) max w while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
   l < r l r m = (l + r) // 2 m (l + r) // 2 l + r l r 2 if is_ok():
      r = m
    else:
      l = m + 1
   is_ok() is_ok r = m r m l = m + 1 l m + 1 m 1 print(r) print r if __name__ == '__main__':
  main2() __name__ == '__main__' __name__ '__main__' main2() main2 n, k = map(int, stdin.readline().split()) map(int, stdin.readline().split()) n def main2():
  def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

  r = sum(w)
  l = max(math.ceil(r/k),max(w))
  while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
  print(r) def main2():
  def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

  r = sum(w)
  l = max(math.ceil(r/k),max(w))
  while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
  print(r) main2 w = list([int(stdin.readline().rstrip()) for i in range(n)]) list([int(stdin.readline().rstrip()) for i in range(n)]) w k = map(int, stdin.readline().split()) map(int, stdin.readline().split()) k
# -*- coding: utf-8 -*-
import sys
from sys import stdin
import math

n, k = map(int, stdin.readline().split())
w = list([int(stdin.readline().rstrip()) for i in range(n)])

def main2():
  def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

  r = sum(w)
  l = max(math.ceil(r/k),max(w))
  while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
  print(r)

if __name__ == '__main__':
  main2()

