def Count_car(n,k,S,P):
    storage = 0
    number = 1
    for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
    if number > k:return 0
    return 1
n,k = list(map(int,input().split()))
total = 0
M = 0
S = []
for _ in range(n):
    number = int(input())
    S.append(number)
import math
P = max(max(S),math.ceil(sum(S)/k))
Q = sum(S)
while True:
    if Q - P <= 1:
        if Count_car(n,k,S,P):
            break
        else:
            P = P+1
            break
    mid = (P+Q)//2
    if Count_car(n,k,S,mid):
        Q = mid
    else:
        P = mid
print(P) def Count_car(n,k,S,P):
    storage = 0
    number = 1
    for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
    if number > k:return 0
    return 1 Count_car storage = 0 storage 0 number = 1 number 1 for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
     i range(n) range n weight = S[i] weight S[i] S i if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
     storage + weight > P storage + weight storage weight P storage = weight storage weight number += 1 number 1 storage += weight storage weight if number > k:return 0
     number > k number k return 1 1 n n k k S S P P n,k = list(map(int,input().split())) n list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split k total = 0 total 0 M = 0 M 0 S = [] S [] for _ in range(n):
    number = int(input())
    S.append(number) _ range(n) range n number = int(input()) number int(input()) int input() input S.append(number) S.append S append number import math math P = max(max(S),math.ceil(sum(S)/k)) P max(max(S),math.ceil(sum(S)/k)) max max(S) max S math.ceil(sum(S)/k) math.ceil math ceil sum(S)/k sum(S) sum S k Q = sum(S) Q sum(S) sum S while True:
    if Q - P <= 1:
        if Count_car(n,k,S,P):
            break
        else:
            P = P+1
            break
    mid = (P+Q)//2
    if Count_car(n,k,S,mid):
        Q = mid
    else:
        P = mid True if Q - P <= 1:
        if Count_car(n,k,S,P):
            break
        else:
            P = P+1
            break
     Q - P <= 1 Q - P Q P 1 if Count_car(n,k,S,P):
            break
        else:
            P = P+1
            break
     Count_car(n,k,S,P) Count_car n k S P break P = P+1 P P+1 P 1 break mid = (P+Q)//2 mid (P+Q)//2 P+Q P Q 2 if Count_car(n,k,S,mid):
        Q = mid
    else:
        P = mid Count_car(n,k,S,mid) Count_car n k S mid Q = mid Q mid P = mid P mid print(P) print P mid = (P+Q)//2 (P+Q)//2 mid number = int(input()) int(input()) number P = mid mid P total = 0 0 total P = max(max(S),math.ceil(sum(S)/k)) max(max(S),math.ceil(sum(S)/k)) P P = P+1 P+1 P def Count_car(n,k,S,P):
    storage = 0
    number = 1
    for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
    if number > k:return 0
    return 1 def Count_car(n,k,S,P):
    storage = 0
    number = 1
    for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
    if number > k:return 0
    return 1 Count_car n,k = list(map(int,input().split())) list(map(int,input().split())) n Q = sum(S) sum(S) Q S = [] [] S k = list(map(int,input().split())) list(map(int,input().split())) k M = 0 0 M Q = mid mid Q
def Count_car(n,k,S,P):
    storage = 0
    number = 1
    for i in range(n):
        weight = S[i]
        if storage + weight > P:
            storage = weight
            number += 1
        else:
            storage += weight
    if number > k:return 0
    return 1
n,k = list(map(int,input().split()))
total = 0
M = 0
S = []
for _ in range(n):
    number = int(input())
    S.append(number)
import math
P = max(max(S),math.ceil(sum(S)/k))
Q = sum(S)
while True:
    if Q - P <= 1:
        if Count_car(n,k,S,P):
            break
        else:
            P = P+1
            break
    mid = (P+Q)//2
    if Count_car(n,k,S,mid):
        Q = mid
    else:
        P = mid
print(P)
