from typing import List


def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
    loaded_baggage_num: int = 0

    for _ in range(truck_num):
        current_weight: int = 0
        while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

    return loaded_baggage_num


def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
    ng: int = max(baggages) - 1
    ok: int = sum(baggages) + 1

    while ok - ng > 1:
        mid = (ng + ok) // 2
        loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
        if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

    return ok


def main():
    n, k = map(int, input().split())
    w: List[int] = []

    for _ in range(n):
        w.append(int(input()))

    P = calc_turck_min_capacity(n, k, w)
    print(P)


if __name__ == "__main__":
    main()
 from typing import List def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
    loaded_baggage_num: int = 0

    for _ in range(truck_num):
        current_weight: int = 0
        while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

    return loaded_baggage_num count_loadable_baggage_num loaded_baggage_num: int = 0 loaded_baggage_num 0 for _ in range(truck_num):
        current_weight: int = 0
        while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

     _ range(truck_num) range truck_num current_weight: int = 0 current_weight 0 while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

     current_weight + baggages[loaded_baggage_num] <= truck_capacity current_weight + baggages[loaded_baggage_num] current_weight baggages[loaded_baggage_num] baggages loaded_baggage_num truck_capacity current_weight += baggages[loaded_baggage_num] current_weight baggages[loaded_baggage_num] baggages loaded_baggage_num loaded_baggage_num += 1 loaded_baggage_num 1 if loaded_baggage_num == baggage_num:
                return baggage_num

     loaded_baggage_num == baggage_num loaded_baggage_num baggage_num return baggage_num baggage_num return loaded_baggage_num loaded_baggage_num baggage_num: int baggage_num truck_num: int truck_num baggages: List[int] baggages truck_capacity: int truck_capacity def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
    ng: int = max(baggages) - 1
    ok: int = sum(baggages) + 1

    while ok - ng > 1:
        mid = (ng + ok) // 2
        loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
        if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

    return ok calc_turck_min_capacity ng: int = max(baggages) - 1 ng max(baggages) - 1 max(baggages) max baggages 1 ok: int = sum(baggages) + 1 ok sum(baggages) + 1 sum(baggages) sum baggages 1 while ok - ng > 1:
        mid = (ng + ok) // 2
        loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
        if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

     ok - ng > 1 ok - ng ok ng 1 mid = (ng + ok) // 2 mid (ng + ok) // 2 ng + ok ng ok 2 loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid) loadable_baggage_num count_loadable_baggage_num(baggage_num, truck_num, baggages, mid) count_loadable_baggage_num baggage_num truck_num baggages mid if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

     loadable_baggage_num >= baggage_num loadable_baggage_num baggage_num ok = mid ok mid ng = mid ng mid return ok ok baggage_num: int baggage_num truck_num: int truck_num baggages: List[int] baggages def main():
    n, k = map(int, input().split())
    w: List[int] = []

    for _ in range(n):
        w.append(int(input()))

    P = calc_turck_min_capacity(n, k, w)
    print(P) main n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k w: List[int] = [] w [] for _ in range(n):
        w.append(int(input()))

     _ range(n) range n w.append(int(input())) w.append w append int(input()) int input() input P = calc_turck_min_capacity(n, k, w) P calc_turck_min_capacity(n, k, w) calc_turck_min_capacity n k w print(P) print P if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
    loaded_baggage_num: int = 0

    for _ in range(truck_num):
        current_weight: int = 0
        while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

    return loaded_baggage_num def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
    loaded_baggage_num: int = 0

    for _ in range(truck_num):
        current_weight: int = 0
        while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

    return loaded_baggage_num count_loadable_baggage_num def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
    ng: int = max(baggages) - 1
    ok: int = sum(baggages) + 1

    while ok - ng > 1:
        mid = (ng + ok) // 2
        loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
        if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

    return ok def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
    ng: int = max(baggages) - 1
    ok: int = sum(baggages) + 1

    while ok - ng > 1:
        mid = (ng + ok) // 2
        loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
        if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

    return ok calc_turck_min_capacity def main():
    n, k = map(int, input().split())
    w: List[int] = []

    for _ in range(n):
        w.append(int(input()))

    P = calc_turck_min_capacity(n, k, w)
    print(P) def main():
    n, k = map(int, input().split())
    w: List[int] = []

    for _ in range(n):
        w.append(int(input()))

    P = calc_turck_min_capacity(n, k, w)
    print(P) main
from typing import List


def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
    loaded_baggage_num: int = 0

    for _ in range(truck_num):
        current_weight: int = 0
        while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
            current_weight += baggages[loaded_baggage_num]
            loaded_baggage_num += 1
            if loaded_baggage_num == baggage_num:
                return baggage_num

    return loaded_baggage_num


def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
    ng: int = max(baggages) - 1
    ok: int = sum(baggages) + 1

    while ok - ng > 1:
        mid = (ng + ok) // 2
        loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
        if loadable_baggage_num >= baggage_num:
            ok = mid
        else:
            ng = mid

    return ok


def main():
    n, k = map(int, input().split())
    w: List[int] = []

    for _ in range(n):
        w.append(int(input()))

    P = calc_turck_min_capacity(n, k, w)
    print(P)


if __name__ == "__main__":
    main()

