


nk=input().split()

n=int(nk[0])
k=int(nk[1])

weight=[int(input()) for i in range(n)]

def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False

low=0
high=sum(weight)
while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
    else:
        low=mid


print(high) nk=input().split() nk input().split() ().split () input split n=int(nk[0]) n int(nk[0]) int nk[0] nk 0 k=int(nk[1]) k int(nk[1]) int nk[1] nk 1 int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input weight=[int(input()) for i in range(n)] weight [int(input()) for i in range(n)] def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False ok load=0 load 0 track=1 track 1 for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

     i range(n) range n load+=weight[i] load weight[i] weight i if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

     load==m load m load=0 load 0 if i!=n-1:
                track+=1
         i!=n-1 i n-1 n 1 track+=1 track 1 elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
         load>m load m if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
         weight[i]>m weight[i] weight i m return False False load=weight[i] load weight[i] weight i track+=1 track 1 continue if track<=k:
        return True
    else:
        return False track<=k track k return True True return False False m m low=0 low 0 high=sum(weight) high sum(weight) sum weight while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
    else:
        low=mid low+1<high low+1 low 1 high mid=(low+high)//2 mid (low+high)//2 low+high low high 2 if ok(mid):
        high=mid
    else:
        low=mid ok(mid) ok mid high=mid high mid low=mid low mid print(high) print high high=mid mid high weight=[int(input()) for i in range(n)] [int(input()) for i in range(n)] weight high=sum(weight) sum(weight) high def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False ok low=mid mid low nk=input().split() input().split() nk k=int(nk[1]) int(nk[1]) k low=0 0 low mid=(low+high)//2 (low+high)//2 mid n=int(nk[0]) int(nk[0]) n



nk=input().split()

n=int(nk[0])
k=int(nk[1])

weight=[int(input()) for i in range(n)]

def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            if weight[i]>m:
                return False
            else:
                load=weight[i]
                track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False

low=0
high=sum(weight)
while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
    else:
        low=mid


print(high)