import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9

n, k = [0, 0]
w = []


def validate(p):
    c = 0
    for i in range(k):
        s = 0
        while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
    return False


def main():
    global n
    global k
    global w
    n, k = map(int, input().split())
    for i in range(n):
        w.append(int(input()))

    # bianry search
    left = 0
    right = 100000 * 10000
    p = right / 2
    while left != right:
        if validate(p):
            right = p
        else:
            left = p + 1
        p = math.floor((left + right) / 2)

    print(p)


if __name__ == '__main__':
    main()
 import math math import string string import itertools itertools import fractions fractions import heapq heapq import collections collections import re re import array array import bisect bisect import sys sys import random random import time time inf = 10**9 inf 10**9 10 9 n, k = [0, 0] n [0, 0] 0 0 k w = [] w [] def validate(p):
    c = 0
    for i in range(k):
        s = 0
        while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
    return False validate c = 0 c 0 for i in range(k):
        s = 0
        while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
     i range(k) range k s = 0 s 0 while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
     s + w[c] <= p s + w[c] s w[c] w c p s = s + w[c] s s + w[c] s w[c] w c c = c + 1 c c + 1 c 1 if c == n:
                return True
     c == n c n return True True return False False p p def main():
    global n
    global k
    global w
    n, k = map(int, input().split())
    for i in range(n):
        w.append(int(input()))

    # bianry search
    left = 0
    right = 100000 * 10000
    p = right / 2
    while left != right:
        if validate(p):
            right = p
        else:
            left = p + 1
        p = math.floor((left + right) / 2)

    print(p) main global n global k global w n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k for i in range(n):
        w.append(int(input()))

    # bianry search
     i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input left = 0 left 0 right = 100000 * 10000 right 100000 * 10000 100000 10000 p = right / 2 p right / 2 right 2 while left != right:
        if validate(p):
            right = p
        else:
            left = p + 1
        p = math.floor((left + right) / 2)

     left != right left right if validate(p):
            right = p
        else:
            left = p + 1
         validate(p) validate p right = p right p left = p + 1 left p + 1 p 1 p = math.floor((left + right) / 2) p math.floor((left + right) / 2) math.floor math floor (left + right) / 2 left + right left right 2 print(p) print p if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main n, k = [0, 0] [0, 0] n inf = 10**9 10**9 inf def main():
    global n
    global k
    global w
    n, k = map(int, input().split())
    for i in range(n):
        w.append(int(input()))

    # bianry search
    left = 0
    right = 100000 * 10000
    p = right / 2
    while left != right:
        if validate(p):
            right = p
        else:
            left = p + 1
        p = math.floor((left + right) / 2)

    print(p) def main():
    global n
    global k
    global w
    n, k = map(int, input().split())
    for i in range(n):
        w.append(int(input()))

    # bianry search
    left = 0
    right = 100000 * 10000
    p = right / 2
    while left != right:
        if validate(p):
            right = p
        else:
            left = p + 1
        p = math.floor((left + right) / 2)

    print(p) main w = [] [] w k = [0, 0] [0, 0] k def validate(p):
    c = 0
    for i in range(k):
        s = 0
        while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
    return False def validate(p):
    c = 0
    for i in range(k):
        s = 0
        while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
    return False validate
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9

n, k = [0, 0]
w = []


def validate(p):
    c = 0
    for i in range(k):
        s = 0
        while s + w[c] <= p:
            s = s + w[c]
            c = c + 1
            if c == n:
                return True
    return False


def main():
    global n
    global k
    global w
    n, k = map(int, input().split())
    for i in range(n):
        w.append(int(input()))

    # bianry search
    left = 0
    right = 100000 * 10000
    p = right / 2
    while left != right:
        if validate(p):
            right = p
        else:
            left = p + 1
        p = math.floor((left + right) / 2)

    print(p)


if __name__ == '__main__':
    main()

