n,k = [int(x) for x in input().split()]

w = []

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

def f(p, k, w):
        tmpk = 0
        tmpw = 0
        cnt = 0

        for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
        return cnt

    
pmin = 1
pmax = sum(w)

while pmin < pmax:
        mid = (pmin + pmax) // 2
        tmp = f(mid, k , w)

        if tmp < n:
                pmin = mid + 1
        else:
                pmax = mid

print(pmin) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n,k = [int(x) for x in input().split()] n [int(x) for x in input().split()] k w = [] w [] for i in range(n):
        w.append(int(input())) i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input def f(p, k, w):
        tmpk = 0
        tmpw = 0
        cnt = 0

        for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
        return cnt

     f tmpk = 0 tmpk 0 tmpw = 0 tmpw 0 cnt = 0 cnt 0 for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
         i w if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
         tmpk < k - 1 tmpk k - 1 k 1 if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                 tmpw + i <= p tmpw + i tmpw i p tmpw += i tmpw i cnt += 1 cnt 1 if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                 i <= p i p tmpk += 1 tmpk 1 tmpw = i tmpw i cnt += 1 cnt 1 break if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
         tmpw + i <= p tmpw + i tmpw i p tmpw += i tmpw i cnt += 1 cnt 1 break return cnt cnt p p k k w w pmin = 1 pmin 1 pmax = sum(w) pmax sum(w) sum w while pmin < pmax:
        mid = (pmin + pmax) // 2
        tmp = f(mid, k , w)

        if tmp < n:
                pmin = mid + 1
        else:
                pmax = mid pmin < pmax pmin pmax mid = (pmin + pmax) // 2 mid (pmin + pmax) // 2 pmin + pmax pmin pmax 2 tmp = f(mid, k , w) tmp f(mid, k , w) f mid k w if tmp < n:
                pmin = mid + 1
        else:
                pmax = mid tmp < n tmp n pmin = mid + 1 pmin mid + 1 mid 1 pmax = mid pmax mid print(pmin) print pmin tmp = f(mid, k , w) f(mid, k , w) tmp pmax = sum(w) sum(w) pmax w = [] [] w def f(p, k, w):
        tmpk = 0
        tmpw = 0
        cnt = 0

        for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
        return cnt

     def f(p, k, w):
        tmpk = 0
        tmpw = 0
        cnt = 0

        for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
        return cnt

     f pmax = mid mid pmax mid = (pmin + pmax) // 2 (pmin + pmax) // 2 mid pmin = 1 1 pmin n,k = [int(x) for x in input().split()] [int(x) for x in input().split()] n k = [int(x) for x in input().split()] [int(x) for x in input().split()] k pmin = mid + 1 mid + 1 pmin
n,k = [int(x) for x in input().split()]

w = []

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

def f(p, k, w):
        tmpk = 0
        tmpw = 0
        cnt = 0

        for i in w:
                if tmpk < k - 1:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                if i <= p:
                                        tmpk += 1
                                        tmpw = i
                                        cnt += 1
                                else:
                                        break
                else:
                        if tmpw + i <= p:
                                tmpw += i
                                cnt += 1
                        else:
                                break
        return cnt

    
pmin = 1
pmax = sum(w)

while pmin < pmax:
        mid = (pmin + pmax) // 2
        tmp = f(mid, k , w)

        if tmp < n:
                pmin = mid + 1
        else:
                pmax = mid

print(pmin)