import sys
import math

def check(k, w, P):
    i = 0
    for t in range(k):
        p = 0
        while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
    return False

def allocate(k, w):
    t = [0] * k
    le = 0
    ri = 100000 * 10000

    while ri - le > 1:
        P = (ri + le) / 2
        if check(k, w, P):
            ri = P
        else:
            le = P
    return ri

if __name__ == "__main__":
    w = sys.stdin.readlines()
    k = int(w[0].split()[1])
    del w[0]
    w = [int(wi) for wi in w]
    print allocate(k, w) import sys sys import math math def check(k, w, P):
    i = 0
    for t in range(k):
        p = 0
        while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
    return False check i = 0 i 0 for t in range(k):
        p = 0
        while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
     t range(k) range k p = 0 p 0 while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
     p + w[i] <= P p + w[i] p w[i] w i P p += w[i] p w[i] w i i += 1 i 1 if i == len(w):
                return True
     i == len(w) i len(w) len w return True True return False False k k w w P P def allocate(k, w):
    t = [0] * k
    le = 0
    ri = 100000 * 10000

    while ri - le > 1:
        P = (ri + le) / 2
        if check(k, w, P):
            ri = P
        else:
            le = P
    return ri allocate t = [0] * k t [0] * k [0] 0 k le = 0 le 0 ri = 100000 * 10000 ri 100000 * 10000 100000 10000 while ri - le > 1:
        P = (ri + le) / 2
        if check(k, w, P):
            ri = P
        else:
            le = P
     ri - le > 1 ri - le ri le 1 P = (ri + le) / 2 P (ri + le) / 2 ri + le ri le 2 if check(k, w, P):
            ri = P
        else:
            le = P
     check(k, w, P) check k w P ri = P ri P le = P le P return ri ri k k w w if __name__ == "__main__":
    w = sys.stdin.readlines()
    k = int(w[0].split()[1])
    del w[0]
    w = [int(wi) for wi in w]
    print allocate(k, w) __name__ == "__main__" __name__ "__main__" w = sys.stdin.readlines() w sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines k = int(w[0].split()[1]) k int(w[0].split()[1]) int w[0].split()[1] [0].split() [0].split [0] w 0 split 1 del w[0] w[0] w 0 int(wi) for wi in w for wi in w wi w for wi in w int(wi) int wi w = [int(wi) for wi in w] w [int(wi) for wi in w] print allocate(k, w) allocate k w k = int(w[0].split()[1]) int(w[0].split()[1]) k def check(k, w, P):
    i = 0
    for t in range(k):
        p = 0
        while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
    return False def check(k, w, P):
    i = 0
    for t in range(k):
        p = 0
        while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
    return False check def allocate(k, w):
    t = [0] * k
    le = 0
    ri = 100000 * 10000

    while ri - le > 1:
        P = (ri + le) / 2
        if check(k, w, P):
            ri = P
        else:
            le = P
    return ri def allocate(k, w):
    t = [0] * k
    le = 0
    ri = 100000 * 10000

    while ri - le > 1:
        P = (ri + le) / 2
        if check(k, w, P):
            ri = P
        else:
            le = P
    return ri allocate w = [int(wi) for wi in w] [int(wi) for wi in w] w w = sys.stdin.readlines() sys.stdin.readlines() w
import sys
import math

def check(k, w, P):
    i = 0
    for t in range(k):
        p = 0
        while p + w[i] <= P:
            p += w[i]
            i += 1
            if i == len(w):
                return True
    return False

def allocate(k, w):
    t = [0] * k
    le = 0
    ri = 100000 * 10000

    while ri - le > 1:
        P = (ri + le) / 2
        if check(k, w, P):
            ri = P
        else:
            le = P
    return ri

if __name__ == "__main__":
    w = sys.stdin.readlines()
    k = int(w[0].split()[1])
    del w[0]
    w = [int(wi) for wi in w]
    print allocate(k, w)