from typing import List


def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool:
    track_num = 1
    tmp_sum = 0
    for w in weights:
        if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
    return True


if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())
    weights = list(map(lambda x: int(input()), range(n)))

    left_weight = max(weights)
    right_weight = 10000 * 100000
    mid_weight = (left_weight + right_weight) // 2
    optimal_P = right_weight

    while left_weight <= right_weight:
        if is_able_to_load(mid_weight, weights, k):
            optimal_P = mid_weight
            right_weight = mid_weight - 1
        else:
            left_weight = mid_weight + 1

        mid_weight = (left_weight + right_weight) // 2

    print(f"{optimal_P}")
 from typing import List def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool:
    track_num = 1
    tmp_sum = 0
    for w in weights:
        if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
    return True is_able_to_load track_num = 1 track_num 1 tmp_sum = 0 tmp_sum 0 for w in weights:
        if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
     w weights if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
     tmp_sum + w <= tmp_P tmp_sum + w tmp_sum w tmp_P tmp_sum += w tmp_sum w track_num += 1 track_num 1 tmp_sum = w tmp_sum w if track_num > track_num_max:
                return False
     track_num > track_num_max track_num track_num_max return False False return True True tmp_P: int tmp_P weights: List[int] weights track_num_max: int track_num_max if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())
    weights = list(map(lambda x: int(input()), range(n)))

    left_weight = max(weights)
    right_weight = 10000 * 100000
    mid_weight = (left_weight + right_weight) // 2
    optimal_P = right_weight

    while left_weight <= right_weight:
        if is_able_to_load(mid_weight, weights, k):
            optimal_P = mid_weight
            right_weight = mid_weight - 1
        else:
            left_weight = mid_weight + 1

        mid_weight = (left_weight + right_weight) // 2

    print(f"{optimal_P}") __name__ == "__main__" __name__ "__main__" n, k = map(lambda x: int(x), input().split()) n map(lambda x: int(x), input().split()) map lambda x: int(x) int(x) int x x input().split() ().split () input split k weights = list(map(lambda x: int(input()), range(n))) weights list(map(lambda x: int(input()), range(n))) list map(lambda x: int(input()), range(n)) map lambda x: int(input()) int(input()) int input() input x range(n) range n left_weight = max(weights) left_weight max(weights) max weights right_weight = 10000 * 100000 right_weight 10000 * 100000 10000 100000 mid_weight = (left_weight + right_weight) // 2 mid_weight (left_weight + right_weight) // 2 left_weight + right_weight left_weight right_weight 2 optimal_P = right_weight optimal_P right_weight while left_weight <= right_weight:
        if is_able_to_load(mid_weight, weights, k):
            optimal_P = mid_weight
            right_weight = mid_weight - 1
        else:
            left_weight = mid_weight + 1

        mid_weight = (left_weight + right_weight) // 2

     left_weight <= right_weight left_weight right_weight if is_able_to_load(mid_weight, weights, k):
            optimal_P = mid_weight
            right_weight = mid_weight - 1
        else:
            left_weight = mid_weight + 1

         is_able_to_load(mid_weight, weights, k) is_able_to_load mid_weight weights k optimal_P = mid_weight optimal_P mid_weight right_weight = mid_weight - 1 right_weight mid_weight - 1 mid_weight 1 left_weight = mid_weight + 1 left_weight mid_weight + 1 mid_weight 1 mid_weight = (left_weight + right_weight) // 2 mid_weight (left_weight + right_weight) // 2 left_weight + right_weight left_weight right_weight 2 print(f"{optimal_P}") print f"{optimal_P}" right_weight = 10000 * 100000 10000 * 100000 right_weight optimal_P = mid_weight mid_weight optimal_P left_weight = mid_weight + 1 mid_weight + 1 left_weight weights = list(map(lambda x: int(input()), range(n))) list(map(lambda x: int(input()), range(n))) weights def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool:
    track_num = 1
    tmp_sum = 0
    for w in weights:
        if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
    return True def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool:
    track_num = 1
    tmp_sum = 0
    for w in weights:
        if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
    return True is_able_to_load mid_weight = (left_weight + right_weight) // 2 (left_weight + right_weight) // 2 mid_weight optimal_P = right_weight right_weight optimal_P mid_weight = (left_weight + right_weight) // 2 (left_weight + right_weight) // 2 mid_weight left_weight = max(weights) max(weights) left_weight k = map(lambda x: int(x), input().split()) map(lambda x: int(x), input().split()) k right_weight = mid_weight - 1 mid_weight - 1 right_weight n, k = map(lambda x: int(x), input().split()) map(lambda x: int(x), input().split()) n
from typing import List


def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool:
    track_num = 1
    tmp_sum = 0
    for w in weights:
        if tmp_sum + w <= tmp_P:
            tmp_sum += w
        else:
            track_num += 1
            tmp_sum = w
            if track_num > track_num_max:
                return False
    return True


if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())
    weights = list(map(lambda x: int(input()), range(n)))

    left_weight = max(weights)
    right_weight = 10000 * 100000
    mid_weight = (left_weight + right_weight) // 2
    optimal_P = right_weight

    while left_weight <= right_weight:
        if is_able_to_load(mid_weight, weights, k):
            optimal_P = mid_weight
            right_weight = mid_weight - 1
        else:
            left_weight = mid_weight + 1

        mid_weight = (left_weight + right_weight) // 2

    print(f"{optimal_P}")

