def main():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))
    minp = max(w)
    maxp = sum(w)
    p = (minp + maxp) // 2
    while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
    print(p)


if __name__ == '__main__':
    main()
 def main():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))
    minp = max(w)
    maxp = sum(w)
    p = (minp + maxp) // 2
    while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
    print(p) main n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () 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 minp = max(w) minp max(w) max w maxp = sum(w) maxp sum(w) sum w p = (minp + maxp) // 2 p (minp + maxp) // 2 minp + maxp minp maxp 2 while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
     minp < maxp minp maxp l = w[0] l w[0] w 0 t = 1 t 1 for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
         ww w[1:] w 1: 1 if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
         l + ww <= p l + ww l ww p l += ww l ww t += 1 t 1 l = ww l ww if t > k:
            minp = p + 1
        else:
            maxp = p
         t > k t k minp = p + 1 minp p + 1 p 1 maxp = p maxp p p = (minp + maxp) // 2 p (minp + maxp) // 2 minp + maxp minp maxp 2 print(p) print p if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))
    minp = max(w)
    maxp = sum(w)
    p = (minp + maxp) // 2
    while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
    print(p) def main():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))
    minp = max(w)
    maxp = sum(w)
    p = (minp + maxp) // 2
    while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
    print(p) main
def main():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))
    minp = max(w)
    maxp = sum(w)
    p = (minp + maxp) // 2
    while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
    print(p)


if __name__ == '__main__':
    main()

