def binary_search(n, k, lw):
    left = 0
    right = max(lw) * n

    while left < right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

    return left

def is_underweight(n, k, lw, p):
    i = 0
    w = 0
    ck = 1
    while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
    return ck <= k

def main():
    n, k = map(int, input().split())
    lw = []
    for _ in range(n):
        lw.append(int(input()))

    p = binary_search(n, k, lw)

    print(p)

if __name__ == '__main__':
    main()
 def binary_search(n, k, lw):
    left = 0
    right = max(lw) * n

    while left < right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

    return left binary_search left = 0 left 0 right = max(lw) * n right max(lw) * n max(lw) max lw n while left < right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

     left < right left right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

     is_underweight(n, k, lw, p=mid) is_underweight n k lw p=mid p mid right = mid right mid left = mid + 1 left mid + 1 mid 1 return left left n n k k lw lw def is_underweight(n, k, lw, p):
    i = 0
    w = 0
    ck = 1
    while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
    return ck <= k is_underweight i = 0 i 0 w = 0 w 0 ck = 1 ck 1 while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
     i < n i n if lw[i] > p:
            return False
         lw[i] > p lw[i] lw i p return False False rest = p - w rest p - w p w if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
     lw[i] <= rest lw[i] lw i rest w += lw[i] w lw[i] lw i i += 1 i 1 w = 0 w 0 ck += 1 ck 1 return ck <= k ck <= k ck k n n k k lw lw p p def main():
    n, k = map(int, input().split())
    lw = []
    for _ in range(n):
        lw.append(int(input()))

    p = binary_search(n, k, lw)

    print(p) main n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k lw = [] lw [] for _ in range(n):
        lw.append(int(input()))

     _ range(n) range n lw.append(int(input())) lw.append lw append int(input()) int input() input p = binary_search(n, k, lw) p binary_search(n, k, lw) binary_search n k lw print(p) print p if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def binary_search(n, k, lw):
    left = 0
    right = max(lw) * n

    while left < right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

    return left def binary_search(n, k, lw):
    left = 0
    right = max(lw) * n

    while left < right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

    return left binary_search def is_underweight(n, k, lw, p):
    i = 0
    w = 0
    ck = 1
    while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
    return ck <= k def is_underweight(n, k, lw, p):
    i = 0
    w = 0
    ck = 1
    while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
    return ck <= k is_underweight def main():
    n, k = map(int, input().split())
    lw = []
    for _ in range(n):
        lw.append(int(input()))

    p = binary_search(n, k, lw)

    print(p) def main():
    n, k = map(int, input().split())
    lw = []
    for _ in range(n):
        lw.append(int(input()))

    p = binary_search(n, k, lw)

    print(p) main
def binary_search(n, k, lw):
    left = 0
    right = max(lw) * n

    while left < right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid
        else:
            left = mid + 1

    return left

def is_underweight(n, k, lw, p):
    i = 0
    w = 0
    ck = 1
    while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
    return ck <= k

def main():
    n, k = map(int, input().split())
    lw = []
    for _ in range(n):
        lw.append(int(input()))

    p = binary_search(n, k, lw)

    print(p)

if __name__ == '__main__':
    main()

