from sys import stdin
from math import ceil

def is_stackable(k,p,w):
    if max(w) > p:
        return False
    s = w[0]
    count = len(w)
    for i in range(1, len(w)):
        if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
    return k >= count

def main():
    n,k = map(int, stdin.readline().split())
    w = [int(line) for line in stdin.readlines()]
    
    left = max(max(w), ceil(sum(w)/k))
    right = (max(w) * ceil(n/k)) + 1
    while True:
        mid = int((left + right) / 2)
        if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1

main() from sys import stdin from math import ceil def is_stackable(k,p,w):
    if max(w) > p:
        return False
    s = w[0]
    count = len(w)
    for i in range(1, len(w)):
        if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
    return k >= count is_stackable if max(w) > p:
        return False
     max(w) > p max(w) max w p return False False s = w[0] s w[0] w 0 count = len(w) count len(w) len w for i in range(1, len(w)):
        if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
     i range(1, len(w)) range 1 len(w) len w if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
     s + w[i] <= p s + w[i] s w[i] w i p s += w[i] s w[i] w i count -= 1 count 1 s = w[i] s w[i] w i return k >= count k >= count k count k k p p w w def main():
    n,k = map(int, stdin.readline().split())
    w = [int(line) for line in stdin.readlines()]
    
    left = max(max(w), ceil(sum(w)/k))
    right = (max(w) * ceil(n/k)) + 1
    while True:
        mid = int((left + right) / 2)
        if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1 main n,k = map(int, stdin.readline().split()) n map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split k int(line) for line in stdin.readlines() for line in stdin.readlines() line stdin.readlines() stdin.readlines stdin readlines for line in stdin.readlines() int(line) int line w = [int(line) for line in stdin.readlines()] w [int(line) for line in stdin.readlines()] left = max(max(w), ceil(sum(w)/k)) left max(max(w), ceil(sum(w)/k)) max max(w) max w ceil(sum(w)/k) ceil sum(w)/k sum(w) sum w k right = (max(w) * ceil(n/k)) + 1 right (max(w) * ceil(n/k)) + 1 max(w) * ceil(n/k) max(w) max w ceil(n/k) ceil n/k n k 1 while True:
        mid = int((left + right) / 2)
        if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1 True mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1 is_stackable(k, mid, w) is_stackable k mid w if not is_stackable(k, mid - 1, w):
                print(mid)
                break
             not is_stackable(k, mid - 1, w) is_stackable(k, mid - 1, w) is_stackable k mid - 1 mid 1 w print(mid) print mid break right = mid right mid if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
             is_stackable(k, mid + 1, w) is_stackable k mid + 1 mid 1 w print(mid + 1) print mid + 1 mid 1 break left = mid + 1 left mid + 1 mid 1 main() main def is_stackable(k,p,w):
    if max(w) > p:
        return False
    s = w[0]
    count = len(w)
    for i in range(1, len(w)):
        if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
    return k >= count def is_stackable(k,p,w):
    if max(w) > p:
        return False
    s = w[0]
    count = len(w)
    for i in range(1, len(w)):
        if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
    return k >= count is_stackable def main():
    n,k = map(int, stdin.readline().split())
    w = [int(line) for line in stdin.readlines()]
    
    left = max(max(w), ceil(sum(w)/k))
    right = (max(w) * ceil(n/k)) + 1
    while True:
        mid = int((left + right) / 2)
        if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1 def main():
    n,k = map(int, stdin.readline().split())
    w = [int(line) for line in stdin.readlines()]
    
    left = max(max(w), ceil(sum(w)/k))
    right = (max(w) * ceil(n/k)) + 1
    while True:
        mid = int((left + right) / 2)
        if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1 main
from sys import stdin
from math import ceil

def is_stackable(k,p,w):
    if max(w) > p:
        return False
    s = w[0]
    count = len(w)
    for i in range(1, len(w)):
        if s + w[i] <= p:
            s += w[i]
            count -= 1
        else:
            s = w[i]
    return k >= count

def main():
    n,k = map(int, stdin.readline().split())
    w = [int(line) for line in stdin.readlines()]
    
    left = max(max(w), ceil(sum(w)/k))
    right = (max(w) * ceil(n/k)) + 1
    while True:
        mid = int((left + right) / 2)
        if is_stackable(k, mid, w):
            if not is_stackable(k, mid - 1, w):
                print(mid)
                break
            right = mid
        else:
            if is_stackable(k, mid + 1, w):
                print(mid + 1)
                break
            left = mid + 1

main()
