def judge_1(arr, p, k):
    index = 0
    n = len(arr)
    for i in range(k):
        weight_sum = 0
        while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
    return index >= n


if __name__ == '__main__':
    n, k = map(int, input().split())
    weight = []
    l, r = 0, 0
    for _ in range(n):
        tmp = int(input())
        weight.append(tmp)
        r += tmp
        l = max(l, tmp)
    ans = r
    while l <= r:
        mid = (l + r) // 2
        if judge_1(weight, mid, k):
            ans = mid
            r = mid - 1
        else:
            l = mid + 1
    print(ans) def judge_1(arr, p, k):
    index = 0
    n = len(arr)
    for i in range(k):
        weight_sum = 0
        while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
    return index >= n judge_1 index = 0 index 0 n = len(arr) n len(arr) len arr for i in range(k):
        weight_sum = 0
        while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
     i range(k) range k weight_sum = 0 weight_sum 0 while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
     weight_sum + arr[index] <= p weight_sum + arr[index] weight_sum arr[index] arr index p weight_sum += arr[index] weight_sum arr[index] arr index index += 1 index 1 if index >= n:
                return True
     index >= n index n return True True return index >= n index >= n index n arr arr p p k k if __name__ == '__main__':
    n, k = map(int, input().split())
    weight = []
    l, r = 0, 0
    for _ in range(n):
        tmp = int(input())
        weight.append(tmp)
        r += tmp
        l = max(l, tmp)
    ans = r
    while l <= r:
        mid = (l + r) // 2
        if judge_1(weight, mid, k):
            ans = mid
            r = mid - 1
        else:
            l = mid + 1
    print(ans) __name__ == '__main__' __name__ '__main__' n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k weight = [] weight [] l, r = 0, 0 l 0 r 0 for _ in range(n):
        tmp = int(input())
        weight.append(tmp)
        r += tmp
        l = max(l, tmp)
     _ range(n) range n tmp = int(input()) tmp int(input()) int input() input weight.append(tmp) weight.append weight append tmp r += tmp r tmp l = max(l, tmp) l max(l, tmp) max l tmp ans = r ans r while l <= r:
        mid = (l + r) // 2
        if judge_1(weight, mid, k):
            ans = mid
            r = mid - 1
        else:
            l = mid + 1
     l <= r l r mid = (l + r) // 2 mid (l + r) // 2 l + r l r 2 if judge_1(weight, mid, k):
            ans = mid
            r = mid - 1
        else:
            l = mid + 1
     judge_1(weight, mid, k) judge_1 weight mid k ans = mid ans mid r = mid - 1 r mid - 1 mid 1 l = mid + 1 l mid + 1 mid 1 print(ans) print ans l = mid + 1 mid + 1 l n, k = map(int, input().split()) map(int, input().split()) n l = max(l, tmp) max(l, tmp) l def judge_1(arr, p, k):
    index = 0
    n = len(arr)
    for i in range(k):
        weight_sum = 0
        while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
    return index >= n def judge_1(arr, p, k):
    index = 0
    n = len(arr)
    for i in range(k):
        weight_sum = 0
        while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
    return index >= n judge_1 l, r = 0, 0 0 l r = mid - 1 mid - 1 r weight = [] [] weight ans = r r ans tmp = int(input()) int(input()) tmp r = 0, 0 0 r r += tmp tmp r ans = mid mid ans mid = (l + r) // 2 (l + r) // 2 mid k = map(int, input().split()) map(int, input().split()) k
def judge_1(arr, p, k):
    index = 0
    n = len(arr)
    for i in range(k):
        weight_sum = 0
        while weight_sum + arr[index] <= p:
            weight_sum += arr[index]
            index += 1
            if index >= n:
                return True
    return index >= n


if __name__ == '__main__':
    n, k = map(int, input().split())
    weight = []
    l, r = 0, 0
    for _ in range(n):
        tmp = int(input())
        weight.append(tmp)
        r += tmp
        l = max(l, tmp)
    ans = r
    while l <= r:
        mid = (l + r) // 2
        if judge_1(weight, mid, k):
            ans = mid
            r = mid - 1
        else:
            l = mid + 1
    print(ans)
