#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
import math 

def is_loadable(load, num_truck, w_list):

    excess = load*num_truck - sum(w_list)
    # print('Minimum Load:', load, num_truck, 'excess:', excess)
    cur_load = 0
    #truck_load = list()
    for w in w_list:
        #print(cur_load, w)
        if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
    if (cur_load and num_truck == 0):
        return False
    #print(truck_load)
    return True

n, num_truck = map(int, sys.stdin.readline().split())

weight = list()
for i in range(n):
    weight.append(int(sys.stdin.readline()))

ave_w = sum(weight) / num_truck
max_w = max(weight)
load = max(max_w, math.ceil(ave_w))
max_ng = load - 1

while True:
    if is_loadable(load, num_truck, weight):
        break
    min_ng = load
    load += 1024

min_ok = load
while True:
    if min_ok == max_ng + 1:
        break
    load = (max_ng + min_ok) // 2
    if is_loadable(load, num_truck, weight):
        min_ok = load
    else:
        max_ng = load

print(min_ok)
 import sys sys import math math def is_loadable(load, num_truck, w_list):

    excess = load*num_truck - sum(w_list)
    # print('Minimum Load:', load, num_truck, 'excess:', excess)
    cur_load = 0
    #truck_load = list()
    for w in w_list:
        #print(cur_load, w)
        if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
    if (cur_load and num_truck == 0):
        return False
    #print(truck_load)
    return True is_loadable excess = load*num_truck - sum(w_list) excess load*num_truck - sum(w_list) load*num_truck load num_truck sum(w_list) sum w_list cur_load = 0 cur_load 0 for w in w_list:
        #print(cur_load, w)
        if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
     w w_list if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
     cur_load + w < load cur_load + w cur_load w load cur_load += w cur_load w elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
         cur_load + w == load cur_load + w cur_load w load cur_load = 0 cur_load 0 num_truck -= 1 num_truck 1 if num_truck < 0:
                return False
         num_truck < 0 num_truck 0 return False False num_truck -= 1 num_truck 1 if num_truck < 0:
                return False
             num_truck < 0 num_truck 0 return False False excess += load - cur_load excess load - cur_load load cur_load if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
             excess < 0 excess 0 return False False cur_load = w cur_load w if (cur_load and num_truck == 0):
        return False
    #print(truck_load)
     cur_load and num_truck == 0 cur_load num_truck == 0 num_truck 0 return False False return True True load load num_truck num_truck w_list w_list n, num_truck = map(int, sys.stdin.readline().split()) n map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split num_truck weight = list() weight list() list for i in range(n):
    weight.append(int(sys.stdin.readline())) i range(n) range n weight.append(int(sys.stdin.readline())) weight.append weight append int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline ave_w = sum(weight) / num_truck ave_w sum(weight) / num_truck sum(weight) sum weight num_truck max_w = max(weight) max_w max(weight) max weight load = max(max_w, math.ceil(ave_w)) load max(max_w, math.ceil(ave_w)) max max_w math.ceil(ave_w) math.ceil math ceil ave_w max_ng = load - 1 max_ng load - 1 load 1 while True:
    if is_loadable(load, num_truck, weight):
        break
    min_ng = load
    load += 1024 True if is_loadable(load, num_truck, weight):
        break
     is_loadable(load, num_truck, weight) is_loadable load num_truck weight break min_ng = load min_ng load load += 1024 load 1024 min_ok = load min_ok load while True:
    if min_ok == max_ng + 1:
        break
    load = (max_ng + min_ok) // 2
    if is_loadable(load, num_truck, weight):
        min_ok = load
    else:
        max_ng = load True if min_ok == max_ng + 1:
        break
     min_ok == max_ng + 1 min_ok max_ng + 1 max_ng 1 break load = (max_ng + min_ok) // 2 load (max_ng + min_ok) // 2 max_ng + min_ok max_ng min_ok 2 if is_loadable(load, num_truck, weight):
        min_ok = load
    else:
        max_ng = load is_loadable(load, num_truck, weight) is_loadable load num_truck weight min_ok = load min_ok load max_ng = load max_ng load print(min_ok) print min_ok min_ok = load load min_ok ave_w = sum(weight) / num_truck sum(weight) / num_truck ave_w max_w = max(weight) max(weight) max_w load += 1024 1024 load max_ng = load load max_ng max_ng = load - 1 load - 1 max_ng weight = list() list() weight load = (max_ng + min_ok) // 2 (max_ng + min_ok) // 2 load def is_loadable(load, num_truck, w_list):

    excess = load*num_truck - sum(w_list)
    # print('Minimum Load:', load, num_truck, 'excess:', excess)
    cur_load = 0
    #truck_load = list()
    for w in w_list:
        #print(cur_load, w)
        if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
    if (cur_load and num_truck == 0):
        return False
    #print(truck_load)
    return True def is_loadable(load, num_truck, w_list):

    excess = load*num_truck - sum(w_list)
    # print('Minimum Load:', load, num_truck, 'excess:', excess)
    cur_load = 0
    #truck_load = list()
    for w in w_list:
        #print(cur_load, w)
        if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
    if (cur_load and num_truck == 0):
        return False
    #print(truck_load)
    return True is_loadable n, num_truck = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) n min_ng = load load min_ng num_truck = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) num_truck load = max(max_w, math.ceil(ave_w)) max(max_w, math.ceil(ave_w)) load min_ok = load load min_ok
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
import math 

def is_loadable(load, num_truck, w_list):

    excess = load*num_truck - sum(w_list)
    # print('Minimum Load:', load, num_truck, 'excess:', excess)
    cur_load = 0
    #truck_load = list()
    for w in w_list:
        #print(cur_load, w)
        if cur_load + w < load:
            cur_load += w
        elif cur_load + w == load:
            #truck_load.append(cur_load + w)
            cur_load = 0
            num_truck -= 1
            if num_truck < 0:
                return False
        else:
            num_truck -= 1
            if num_truck < 0:
                return False
            excess += load - cur_load
            if excess < 0:
                return False
            #print(cur_load, 'is added')
            #truck_load.append(cur_load)
            cur_load = w

    #truck_load.append(cur_load)
    if (cur_load and num_truck == 0):
        return False
    #print(truck_load)
    return True

n, num_truck = map(int, sys.stdin.readline().split())

weight = list()
for i in range(n):
    weight.append(int(sys.stdin.readline()))

ave_w = sum(weight) / num_truck
max_w = max(weight)
load = max(max_w, math.ceil(ave_w))
max_ng = load - 1

while True:
    if is_loadable(load, num_truck, weight):
        break
    min_ng = load
    load += 1024

min_ok = load
while True:
    if min_ok == max_ng + 1:
        break
    load = (max_ng + min_ok) // 2
    if is_loadable(load, num_truck, weight):
        min_ok = load
    else:
        max_ng = load

print(min_ok)

