def binarytruck(maxweight,truck,num):
    disp = 0
    for n in range(num):
        if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
    return truck > 0
num,truck = (int(n) for n in input().split(' '))
global targ
targ = []
for n in range(num):
    targ.append(int(input()))
best = max(targ) - 1
worst = sum(targ)
maxweight = (best + worst ) // 2
cnt = 0
while best != worst - 1:
    cnt += 1
    if binarytruck(maxweight,truck,num):
        worst = maxweight
        maxweight = (best + maxweight) // 2

    else:
        best = maxweight
        maxweight = (worst + maxweight) // 2
print(worst) def binarytruck(maxweight,truck,num):
    disp = 0
    for n in range(num):
        if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
    return truck > 0 binarytruck disp = 0 disp 0 for n in range(num):
        if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
     n range(num) range num if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
     maxweight - targ[n] - disp < 0 maxweight - targ[n] - disp maxweight - targ[n] maxweight targ[n] targ n disp 0 disp = targ[n] disp targ[n] targ n truck -= 1 truck 1 disp += targ[n] disp targ[n] targ n return truck > 0 truck > 0 truck 0 maxweight maxweight truck truck num num int(n) for n in input().split(' ') for n in input().split(' ') n input().split(' ') ().split () input split ' ' for n in input().split(' ') int(n) int n num,truck = (int(n) for n in input().split(' ')) num (int(n) for n in input().split(' ')) truck global targ targ = [] targ [] for n in range(num):
    targ.append(int(input())) n range(num) range num targ.append(int(input())) targ.append targ append int(input()) int input() input best = max(targ) - 1 best max(targ) - 1 max(targ) max targ 1 worst = sum(targ) worst sum(targ) sum targ maxweight = (best + worst ) // 2 maxweight (best + worst ) // 2 best + worst best worst 2 cnt = 0 cnt 0 while best != worst - 1:
    cnt += 1
    if binarytruck(maxweight,truck,num):
        worst = maxweight
        maxweight = (best + maxweight) // 2

    else:
        best = maxweight
        maxweight = (worst + maxweight) // 2 best != worst - 1 best worst - 1 worst 1 cnt += 1 cnt 1 if binarytruck(maxweight,truck,num):
        worst = maxweight
        maxweight = (best + maxweight) // 2

    else:
        best = maxweight
        maxweight = (worst + maxweight) // 2 binarytruck(maxweight,truck,num) binarytruck maxweight truck num worst = maxweight worst maxweight maxweight = (best + maxweight) // 2 maxweight (best + maxweight) // 2 best + maxweight best maxweight 2 best = maxweight best maxweight maxweight = (worst + maxweight) // 2 maxweight (worst + maxweight) // 2 worst + maxweight worst maxweight 2 print(worst) print worst cnt += 1 1 cnt maxweight = (best + maxweight) // 2 (best + maxweight) // 2 maxweight global targ maxweight = (worst + maxweight) // 2 (worst + maxweight) // 2 maxweight cnt = 0 0 cnt num,truck = (int(n) for n in input().split(' ')) (int(n) for n in input().split(' ')) num maxweight = (best + worst ) // 2 (best + worst ) // 2 maxweight truck = (int(n) for n in input().split(' ')) (int(n) for n in input().split(' ')) truck worst = maxweight maxweight worst worst = sum(targ) sum(targ) worst best = max(targ) - 1 max(targ) - 1 best best = maxweight maxweight best def binarytruck(maxweight,truck,num):
    disp = 0
    for n in range(num):
        if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
    return truck > 0 def binarytruck(maxweight,truck,num):
    disp = 0
    for n in range(num):
        if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
    return truck > 0 binarytruck targ = [] [] targ
def binarytruck(maxweight,truck,num):
    disp = 0
    for n in range(num):
        if maxweight - targ[n] - disp < 0:
            disp = targ[n]
            truck -= 1
        else:
            disp += targ[n]
    return truck > 0
num,truck = (int(n) for n in input().split(' '))
global targ
targ = []
for n in range(num):
    targ.append(int(input()))
best = max(targ) - 1
worst = sum(targ)
maxweight = (best + worst ) // 2
cnt = 0
while best != worst - 1:
    cnt += 1
    if binarytruck(maxweight,truck,num):
        worst = maxweight
        maxweight = (best + maxweight) // 2

    else:
        best = maxweight
        maxweight = (worst + maxweight) // 2
print(worst)