def p_is_smaller(p):
    total = 0
    number_of_track = 1
    for w in W:
        total += w
        if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
    return 0

if __name__ == "__main__":
    n, k = map(int, input().split())
    W = [int(input()) for _ in range(n)]
    left, right = max(W), sum(W)
    while right > left:
        mid = (left + right) // 2
        if p_is_smaller(mid):
            left = mid + 1
        else:
            right = mid
    print(right) def p_is_smaller(p):
    total = 0
    number_of_track = 1
    for w in W:
        total += w
        if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
    return 0 p_is_smaller total = 0 total 0 number_of_track = 1 number_of_track 1 for w in W:
        total += w
        if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
     w W total += w total w if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
     total > p total p number_of_track += 1 number_of_track 1 if number_of_track > k:
                return 1
             number_of_track > k number_of_track k return 1 1 total = w total w return 0 0 p p if __name__ == "__main__":
    n, k = map(int, input().split())
    W = [int(input()) for _ in range(n)]
    left, right = max(W), sum(W)
    while right > left:
        mid = (left + right) // 2
        if p_is_smaller(mid):
            left = mid + 1
        else:
            right = mid
    print(right) __name__ == "__main__" __name__ "__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 W = [int(input()) for _ in range(n)] W [int(input()) for _ in range(n)] left, right = max(W), sum(W) left max(W) max W right sum(W) sum W while right > left:
        mid = (left + right) // 2
        if p_is_smaller(mid):
            left = mid + 1
        else:
            right = mid
     right > left right left mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if p_is_smaller(mid):
            left = mid + 1
        else:
            right = mid
     p_is_smaller(mid) p_is_smaller mid left = mid + 1 left mid + 1 mid 1 right = mid right mid print(right) print right right = max(W), sum(W) sum(W) right left, right = max(W), sum(W) max(W) left W = [int(input()) for _ in range(n)] [int(input()) for _ in range(n)] W right = mid mid right left = mid + 1 mid + 1 left mid = (left + right) // 2 (left + right) // 2 mid k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n def p_is_smaller(p):
    total = 0
    number_of_track = 1
    for w in W:
        total += w
        if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
    return 0 def p_is_smaller(p):
    total = 0
    number_of_track = 1
    for w in W:
        total += w
        if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
    return 0 p_is_smaller
def p_is_smaller(p):
    total = 0
    number_of_track = 1
    for w in W:
        total += w
        if total > p:
            number_of_track += 1
            if number_of_track > k:
                return 1
            total = w
    return 0

if __name__ == "__main__":
    n, k = map(int, input().split())
    W = [int(input()) for _ in range(n)]
    left, right = max(W), sum(W)
    while right > left:
        mid = (left + right) // 2
        if p_is_smaller(mid):
            left = mid + 1
        else:
            right = mid
    print(right)
