import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def n_load(p, k, n, w):
    i = 0
    load = 0
    tr = 0
    while i < n:
        if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
    return i

def main():
    n, k = list(map(int, input().strip().split()))
    w = [0] * n
    for i in range(n):
        w[i] = int(input().strip())
    l = 0
    r = INF
    while l +1 < r:
        mid = (l + r) // 2
        ntr = n_load(mid, k, n, w)
        # print('ntr: ', ntr, l, r)
        if ntr == n:
            r = mid
        else:
            l = mid
    print(r)

if __name__ == '__main__':
    main()
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from operator import itemgetter sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 INF = 10**30 INF 10**30 10 30 def n_load(p, k, n, w):
    i = 0
    load = 0
    tr = 0
    while i < n:
        if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
    return i n_load i = 0 i 0 load = 0 load 0 tr = 0 tr 0 while i < n:
        if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
     i < n i n if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
     load + w[i] <= p load + w[i] load w[i] w i p load += w[i] load w[i] w i i += 1 i 1 tr += 1 tr 1 if tr == k:
                break
             tr == k tr k break load = 0 load 0 return i i p p k k n n w w def main():
    n, k = list(map(int, input().strip().split()))
    w = [0] * n
    for i in range(n):
        w[i] = int(input().strip())
    l = 0
    r = INF
    while l +1 < r:
        mid = (l + r) // 2
        ntr = n_load(mid, k, n, w)
        # print('ntr: ', ntr, l, r)
        if ntr == n:
            r = mid
        else:
            l = mid
    print(r) main n, k = list(map(int, input().strip().split())) n list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split k w = [0] * n w [0] * n [0] 0 n for i in range(n):
        w[i] = int(input().strip())
     i range(n) range n w[i] = int(input().strip()) w[i] w i int(input().strip()) int input().strip() ().strip () input strip l = 0 l 0 r = INF r INF while l +1 < r:
        mid = (l + r) // 2
        ntr = n_load(mid, k, n, w)
        # print('ntr: ', ntr, l, r)
        if ntr == n:
            r = mid
        else:
            l = mid
     l +1 < r l +1 l 1 r mid = (l + r) // 2 mid (l + r) // 2 l + r l r 2 ntr = n_load(mid, k, n, w) ntr n_load(mid, k, n, w) n_load mid k n w if ntr == n:
            r = mid
        else:
            l = mid
     ntr == n ntr n r = mid r mid l = mid l mid print(r) print r if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def n_load(p, k, n, w):
    i = 0
    load = 0
    tr = 0
    while i < n:
        if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
    return i def n_load(p, k, n, w):
    i = 0
    load = 0
    tr = 0
    while i < n:
        if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
    return i n_load def main():
    n, k = list(map(int, input().strip().split()))
    w = [0] * n
    for i in range(n):
        w[i] = int(input().strip())
    l = 0
    r = INF
    while l +1 < r:
        mid = (l + r) // 2
        ntr = n_load(mid, k, n, w)
        # print('ntr: ', ntr, l, r)
        if ntr == n:
            r = mid
        else:
            l = mid
    print(r) def main():
    n, k = list(map(int, input().strip().split()))
    w = [0] * n
    for i in range(n):
        w[i] = int(input().strip())
    l = 0
    r = INF
    while l +1 < r:
        mid = (l + r) // 2
        ntr = n_load(mid, k, n, w)
        # print('ntr: ', ntr, l, r)
        if ntr == n:
            r = mid
        else:
            l = mid
    print(r) main input = sys.stdin.readline sys.stdin.readline input INF = 10**30 10**30 INF
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def n_load(p, k, n, w):
    i = 0
    load = 0
    tr = 0
    while i < n:
        if load + w[i] <= p:
            load += w[i]
            i += 1
        else:
            tr += 1
            if tr == k:
                break
            load = 0
    return i

def main():
    n, k = list(map(int, input().strip().split()))
    w = [0] * n
    for i in range(n):
        w[i] = int(input().strip())
    l = 0
    r = INF
    while l +1 < r:
        mid = (l + r) // 2
        ntr = n_load(mid, k, n, w)
        # print('ntr: ', ntr, l, r)
        if ntr == n:
            r = mid
        else:
            l = mid
    print(r)

if __name__ == '__main__':
    main()

