n,k = map(int,input().split())
wi = []
for _ in range(n):
    wi.append(int(input()))

def isPossibleCarry(k, wi, P):
    track_num = 1
    track_weight = 0
    
    for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
    return track_num <= k or (track_num == k+1 and track_weight==0)

left_P = 1
right_P = sum(wi)
while left_P < right_P:
    mid = int((left_P + right_P) /2)
    if(isPossibleCarry(k, wi, mid)):
        right_P = mid
    else:
        left_P = mid + 1
if(isPossibleCarry(k, wi, mid)):
    print(mid)
else:
    print(left_P)
 n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k wi = [] wi [] for _ in range(n):
    wi.append(int(input())) _ range(n) range n wi.append(int(input())) wi.append wi append int(input()) int input() input def isPossibleCarry(k, wi, P):
    track_num = 1
    track_weight = 0
    
    for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
    return track_num <= k or (track_num == k+1 and track_weight==0) isPossibleCarry track_num = 1 track_num 1 track_weight = 0 track_weight 0 for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
     w wi if(w > P):
            return False
        
         w > P w P return False False if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
     track_weight + w < P track_weight + w track_weight w P track_weight = track_weight + w track_weight track_weight + w track_weight w elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
         track_weight + w == P track_weight + w track_weight w P track_num += 1 track_num 1 track_weight = 0 track_weight 0 track_num += 1 track_num 1 track_weight = w track_weight w if(track_num > k):
                return False
            
     track_num > k track_num k return False False return track_num <= k or (track_num == k+1 and track_weight==0) track_num <= k or (track_num == k+1 and track_weight==0) track_num <= k track_num k track_num == k+1 and track_weight==0 track_num == k+1 track_num k+1 k 1 track_weight==0 track_weight 0 k k wi wi P P left_P = 1 left_P 1 right_P = sum(wi) right_P sum(wi) sum wi while left_P < right_P:
    mid = int((left_P + right_P) /2)
    if(isPossibleCarry(k, wi, mid)):
        right_P = mid
    else:
        left_P = mid + 1 left_P < right_P left_P right_P mid = int((left_P + right_P) /2) mid int((left_P + right_P) /2) int (left_P + right_P) /2 left_P + right_P left_P right_P 2 if(isPossibleCarry(k, wi, mid)):
        right_P = mid
    else:
        left_P = mid + 1 isPossibleCarry(k, wi, mid) isPossibleCarry k wi mid right_P = mid right_P mid left_P = mid + 1 left_P mid + 1 mid 1 if(isPossibleCarry(k, wi, mid)):
    print(mid)
else:
    print(left_P) isPossibleCarry(k, wi, mid) isPossibleCarry k wi mid print(mid) print mid print(left_P) print left_P left_P = mid + 1 mid + 1 left_P def isPossibleCarry(k, wi, P):
    track_num = 1
    track_weight = 0
    
    for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
    return track_num <= k or (track_num == k+1 and track_weight==0) def isPossibleCarry(k, wi, P):
    track_num = 1
    track_weight = 0
    
    for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
    return track_num <= k or (track_num == k+1 and track_weight==0) isPossibleCarry k = map(int,input().split()) map(int,input().split()) k mid = int((left_P + right_P) /2) int((left_P + right_P) /2) mid wi = [] [] wi right_P = sum(wi) sum(wi) right_P n,k = map(int,input().split()) map(int,input().split()) n left_P = 1 1 left_P right_P = mid mid right_P
n,k = map(int,input().split())
wi = []
for _ in range(n):
    wi.append(int(input()))

def isPossibleCarry(k, wi, P):
    track_num = 1
    track_weight = 0
    
    for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
    return track_num <= k or (track_num == k+1 and track_weight==0)

left_P = 1
right_P = sum(wi)
while left_P < right_P:
    mid = int((left_P + right_P) /2)
    if(isPossibleCarry(k, wi, mid)):
        right_P = mid
    else:
        left_P = mid + 1
if(isPossibleCarry(k, wi, mid)):
    print(mid)
else:
    print(left_P)

