import math

def search(cap, loads, num_tracks):
    num = 0
    capacity = cap
    tracks = num_tracks

    for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
    return num

def Main():
    N, K = map(int, input().split())
    loads = list()

    for i in range(N):
        l = int(input())
        loads.append(l)

    pl = 0
    pr = sum(loads)

    pm = int( (pl + pr)/2.0 ) + 1
    pm_ = 0

    while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm

Main() import math math def search(cap, loads, num_tracks):
    num = 0
    capacity = cap
    tracks = num_tracks

    for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
    return num search num = 0 num 0 capacity = cap capacity cap tracks = num_tracks tracks num_tracks for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
     l loads if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
     capacity >= l capacity l capacity -= l capacity l num += 1 num 1 if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
     tracks > 1 tracks 1 tracks -= 1 tracks 1 capacity = cap capacity cap if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
             capacity >= l capacity l capacity -= l capacity l num += 1 num 1 break break return num num cap cap loads loads num_tracks num_tracks def Main():
    N, K = map(int, input().split())
    loads = list()

    for i in range(N):
        l = int(input())
        loads.append(l)

    pl = 0
    pr = sum(loads)

    pm = int( (pl + pr)/2.0 ) + 1
    pm_ = 0

    while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm Main N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K loads = list() loads list() list for i in range(N):
        l = int(input())
        loads.append(l)

     i range(N) range N l = int(input()) l int(input()) int input() input loads.append(l) loads.append loads append l pl = 0 pl 0 pr = sum(loads) pr sum(loads) sum loads pm = int( (pl + pr)/2.0 ) + 1 pm int( (pl + pr)/2.0 ) + 1 int( (pl + pr)/2.0 ) int (pl + pr)/2.0 pl + pr pl pr 2.0 1 pm_ = 0 pm_ 0 while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm pl < pr pl pr pm = math.ceil( (pl + pr)/2.0 ) pm math.ceil( (pl + pr)/2.0 ) math.ceil math ceil (pl + pr)/2.0 pl + pr pl pr 2.0 nl = search( pl, loads, K) nl search( pl, loads, K) search pl loads K nm = search( pm, loads, K) nm search( pm, loads, K) search pm loads K nr = search( pr, loads, K) nr search( pr, loads, K) search pr loads K if pm_ == pm:
            print(pm)
            break

         pm_ == pm pm_ pm print(pm) print pm break if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm nm == nr nm nr pl = pl pl pl pr = pm pr pm pm_ = pm pm_ pm pl = pm pl pm pr = pr pr pr pm_ = pm pm_ pm Main() Main def Main():
    N, K = map(int, input().split())
    loads = list()

    for i in range(N):
        l = int(input())
        loads.append(l)

    pl = 0
    pr = sum(loads)

    pm = int( (pl + pr)/2.0 ) + 1
    pm_ = 0

    while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm def Main():
    N, K = map(int, input().split())
    loads = list()

    for i in range(N):
        l = int(input())
        loads.append(l)

    pl = 0
    pr = sum(loads)

    pm = int( (pl + pr)/2.0 ) + 1
    pm_ = 0

    while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm Main def search(cap, loads, num_tracks):
    num = 0
    capacity = cap
    tracks = num_tracks

    for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
    return num def search(cap, loads, num_tracks):
    num = 0
    capacity = cap
    tracks = num_tracks

    for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
    return num search
import math

def search(cap, loads, num_tracks):
    num = 0
    capacity = cap
    tracks = num_tracks

    for l in loads :
        if capacity >= l: 
            capacity -= l
            num += 1
        else:
            if tracks > 1:
                tracks -= 1
                capacity = cap

                if capacity >= l:
                    capacity -= l
                    num += 1
                else:
                    break
            else:
                break
    return num

def Main():
    N, K = map(int, input().split())
    loads = list()

    for i in range(N):
        l = int(input())
        loads.append(l)

    pl = 0
    pr = sum(loads)

    pm = int( (pl + pr)/2.0 ) + 1
    pm_ = 0

    while pl < pr :
        pm = math.ceil( (pl + pr)/2.0 )

        nl = search( pl, loads, K)
        nm = search( pm, loads, K)
        nr = search( pr, loads, K)

        if pm_ == pm:
            print(pm)
            break

        if nm == nr :
            pl = pl
            pr = pm
            pm_ = pm
        else :
            pl = pm
            pr = pr
            pm_ = pm

Main()
