from collections import deque
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N,K = map(int,input().split())
 
table = [0]*N
max_W = 0
 
for i in range(N):
    table[i] = int(input())
    max_W = max(max_W,table[i])
 
 
left = max_W;right = 10000*100000;mid = (left+right)//2;
ans = right
 
 
def is_ok(tmp_P):
 
    num_track = 1
    tmp_sum = 0
    for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
    return True
 
 
while left <= right:
 
    if is_ok(mid) == True:
        ans = mid
        right = mid-1
    else:
        left = mid+1
 
    mid = (left+right)//2;
 
 
print("%d"%(ans)) from collections import deque from enum import Enum import sys sys import math math BIG_NUM = 2000000000 BIG_NUM 2000000000 MOD = 1000000007 MOD 1000000007 EPS = 0.000000001 EPS 0.000000001 N,K = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K table = [0]*N table [0]*N [0] 0 N max_W = 0 max_W 0 for i in range(N):
    table[i] = int(input())
    max_W = max(max_W,table[i])
 
  i range(N) range N table[i] = int(input()) table[i] table i int(input()) int input() input max_W = max(max_W,table[i]) max_W max(max_W,table[i]) max max_W table[i] table i left = max_W left max_W right = 10000*100000 right 10000*100000 10000 100000 mid = (left+right)//2 mid (left+right)//2 left+right left right 2 ans = right ans right def is_ok(tmp_P):
 
    num_track = 1
    tmp_sum = 0
    for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
    return True
 
  is_ok num_track = 1 num_track 1 tmp_sum = 0 tmp_sum 0 for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
     i range(N) range N if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
     tmp_sum+table[i] <= tmp_P tmp_sum+table[i] tmp_sum table[i] table i tmp_P tmp_sum += table[i] tmp_sum table[i] table i num_track += 1 num_track 1 tmp_sum = table[i] tmp_sum table[i] table i if num_track > K:
                return False
 
     num_track > K num_track K return False False return True True tmp_P tmp_P while left <= right:
 
    if is_ok(mid) == True:
        ans = mid
        right = mid-1
    else:
        left = mid+1
 
    mid = (left+right)//2;
 
  left <= right left right if is_ok(mid) == True:
        ans = mid
        right = mid-1
    else:
        left = mid+1
 
     is_ok(mid) == True is_ok(mid) is_ok mid True ans = mid ans mid right = mid-1 right mid-1 mid 1 left = mid+1 left mid+1 mid 1 mid = (left+right)//2 mid (left+right)//2 left+right left right 2 print("%d"%(ans)) print "%d"%(ans) "%d" ans MOD = 1000000007 1000000007 MOD BIG_NUM = 2000000000 2000000000 BIG_NUM EPS = 0.000000001 0.000000001 EPS max_W = 0 0 max_W left = max_W max_W left left = mid+1 mid+1 left max_W = max(max_W,table[i]) max(max_W,table[i]) max_W mid = (left+right)//2 (left+right)//2 mid N,K = map(int,input().split()) map(int,input().split()) N ans = mid mid ans K = map(int,input().split()) map(int,input().split()) K ans = right right ans right = mid-1 mid-1 right right = 10000*100000 10000*100000 right def is_ok(tmp_P):
 
    num_track = 1
    tmp_sum = 0
    for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
    return True
 
  def is_ok(tmp_P):
 
    num_track = 1
    tmp_sum = 0
    for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
    return True
 
  is_ok mid = (left+right)//2 (left+right)//2 mid table = [0]*N [0]*N table
from collections import deque
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N,K = map(int,input().split())
 
table = [0]*N
max_W = 0
 
for i in range(N):
    table[i] = int(input())
    max_W = max(max_W,table[i])
 
 
left = max_W;right = 10000*100000;mid = (left+right)//2;
ans = right
 
 
def is_ok(tmp_P):
 
    num_track = 1
    tmp_sum = 0
    for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
    return True
 
 
while left <= right:
 
    if is_ok(mid) == True:
        ans = mid
        right = mid-1
    else:
        left = mid+1
 
    mid = (left+right)//2;
 
 
print("%d"%(ans))
