import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())

    products = [int(input()) for _ in range(n)]

    left = 1
    right = 10000 * 100000  # 最大重量 × 最大貨物数

    while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

    print(right)


def allocate(capacity, truckNum, products):
    # print("===== start allocation capacity:{}======".format(capacity))
    v = 0
    tmp = 0
    truckNum -= 1
    while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

    return v


if __name__ == '__main__':
    main()
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    n, k = map(int, input().split())

    products = [int(input()) for _ in range(n)]

    left = 1
    right = 10000 * 100000  # 最大重量 × 最大貨物数

    while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

    print(right) main n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input products = [int(input()) for _ in range(n)] products [int(input()) for _ in range(n)] left = 1 left 1 right = 10000 * 100000 right 10000 * 100000 10000 100000 while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

     left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 v = allocate(mid, k, products) v allocate(mid, k, products) allocate mid k products if n <= v:
            right = mid
        else:
            left = mid + 1

     n <= v n v right = mid right mid left = mid + 1 left mid + 1 mid 1 print(right) print right def allocate(capacity, truckNum, products):
    # print("===== start allocation capacity:{}======".format(capacity))
    v = 0
    tmp = 0
    truckNum -= 1
    while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

    return v allocate v = 0 v 0 tmp = 0 tmp 0 truckNum -= 1 truckNum 1 while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

     len(products) > v len(products) len products v product = products[v] product products[v] products v if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

         product > capacity product capacity return 0 0 if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

         tmp + product <= capacity tmp + product tmp product capacity tmp += product tmp product if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

         truckNum > 0 truckNum 0 truckNum -= 1 truckNum 1 tmp = product tmp product return v v v += 1 v 1 return v v capacity capacity truckNum truckNum products products if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, k = map(int, input().split())

    products = [int(input()) for _ in range(n)]

    left = 1
    right = 10000 * 100000  # 最大重量 × 最大貨物数

    while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

    print(right) def main():
    n, k = map(int, input().split())

    products = [int(input()) for _ in range(n)]

    left = 1
    right = 10000 * 100000  # 最大重量 × 最大貨物数

    while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

    print(right) main input = sys.stdin.readline sys.stdin.readline input def allocate(capacity, truckNum, products):
    # print("===== start allocation capacity:{}======".format(capacity))
    v = 0
    tmp = 0
    truckNum -= 1
    while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

    return v def allocate(capacity, truckNum, products):
    # print("===== start allocation capacity:{}======".format(capacity))
    v = 0
    tmp = 0
    truckNum -= 1
    while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

    return v allocate
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())

    products = [int(input()) for _ in range(n)]

    left = 1
    right = 10000 * 100000  # 最大重量 × 最大貨物数

    while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

    print(right)


def allocate(capacity, truckNum, products):
    # print("===== start allocation capacity:{}======".format(capacity))
    v = 0
    tmp = 0
    truckNum -= 1
    while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

    return v


if __name__ == '__main__':
    main()

