import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")
       
    
def check(k, P, W):
    count = 1
    tmp_sum = 0
    for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
    if count <= k:
        return True
    else:
        return False

def main():
    n, k, *W = MLI()
    
    lb = max(W)
    ub = sum(W)
    
    while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
    if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                
if __name__ == "__main__":
    main()  import bisect bisect import math math import sys sys from collections import Counter, defaultdict, deque from copy import copy, deepcopy from heapq import heapify, heappop, heappush from itertools import combinations, permutations from queue import Queue read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines def SI():
    return int(readline()) SI return int(readline()) int(readline()) int readline() readline def MI():
    return map(int, readline().split()) MI return map(int, readline().split()) map(int, readline().split()) map int readline().split() ().split () readline split def MLI():
    return map(int, open(0).read().split()) MLI return map(int, open(0).read().split()) map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split inf = float("inf") inf float("inf") float "inf" def check(k, P, W):
    count = 1
    tmp_sum = 0
    for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
    if count <= k:
        return True
    else:
        return False check count = 1 count 1 tmp_sum = 0 tmp_sum 0 for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
     w W if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
     tmp_sum + w <= P tmp_sum + w tmp_sum w P tmp_sum += w tmp_sum w tmp_sum = w tmp_sum w count += 1 count 1 if count <= k:
        return True
    else:
        return False count <= k count k return True True return False False k k P P W W def main():
    n, k, *W = MLI()
    
    lb = max(W)
    ub = sum(W)
    
    while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
    if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                 main n, k, *W = MLI() n MLI() MLI k *W W lb = max(W) lb max(W) max W ub = sum(W) ub sum(W) sum W while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
     ub - lb > 1 ub - lb ub lb 1 P = (lb + ub) // 2 P (lb + ub) // 2 lb + ub lb ub 2 if check(k, P, W):
            ub = P
        else:
            lb = P
    
     check(k, P, W) check k P W ub = P ub P lb = P lb P if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                 check(k, lb, W) check k lb W print(lb) print lb print(ub) print ub if __name__ == "__main__":
    main()  __name__ == "__main__" __name__ "__main__" main() main readlines = sys.stdin.readlines sys.stdin.readlines readlines def MLI():
    return map(int, open(0).read().split()) def MLI():
    return map(int, open(0).read().split()) MLI readline = sys.stdin.readline sys.stdin.readline readline def MI():
    return map(int, readline().split()) def MI():
    return map(int, readline().split()) MI def SI():
    return int(readline()) def SI():
    return int(readline()) SI read = sys.stdin.read sys.stdin.read read def main():
    n, k, *W = MLI()
    
    lb = max(W)
    ub = sum(W)
    
    while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
    if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                 def main():
    n, k, *W = MLI()
    
    lb = max(W)
    ub = sum(W)
    
    while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
    if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                 main def check(k, P, W):
    count = 1
    tmp_sum = 0
    for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
    if count <= k:
        return True
    else:
        return False def check(k, P, W):
    count = 1
    tmp_sum = 0
    for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
    if count <= k:
        return True
    else:
        return False check inf = float("inf") float("inf") inf
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")
       
    
def check(k, P, W):
    count = 1
    tmp_sum = 0
    for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
    if count <= k:
        return True
    else:
        return False

def main():
    n, k, *W = MLI()
    
    lb = max(W)
    ub = sum(W)
    
    while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
    if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                
if __name__ == "__main__":
    main() 
