def check(p, n, w, k):
	temp = 0
	for i in range(n):
		if w[i] > p:
			return False
		if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		temp += w[i]
	if k == 0:
		return False
	else:
		return True

def main():
	n, k = map(int,input().split())
	w = []
	for _ in range(n):
		w += [int(input())]
	pmin = 0
	pmax = 10**10
	while True:
		if pmin >= pmax:
			print(pmin)
			break
		if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1

main() def check(p, n, w, k):
	temp = 0
	for i in range(n):
		if w[i] > p:
			return False
		if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		temp += w[i]
	if k == 0:
		return False
	else:
		return True check temp = 0 temp 0 for i in range(n):
		if w[i] > p:
			return False
		if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		temp += w[i]
	 i range(n) range n if w[i] > p:
			return False
		 w[i] > p w[i] w i p return False False if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		 temp + w[i] > p temp + w[i] temp w[i] w i p temp = 0 temp 0 k -= 1 k 1 if k < 0:
				return False
		 k < 0 k 0 return False False temp += w[i] temp w[i] w i if k == 0:
		return False
	else:
		return True k == 0 k 0 return False False return True True p p n n w w k k def main():
	n, k = map(int,input().split())
	w = []
	for _ in range(n):
		w += [int(input())]
	pmin = 0
	pmax = 10**10
	while True:
		if pmin >= pmax:
			print(pmin)
			break
		if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1 main n, k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k w = [] w [] for _ in range(n):
		w += [int(input())]
	 _ range(n) range n w += [int(input())] w [int(input())] int(input()) int input() input pmin = 0 pmin 0 pmax = 10**10 pmax 10**10 10 10 while True:
		if pmin >= pmax:
			print(pmin)
			break
		if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1 True if pmin >= pmax:
			print(pmin)
			break
		 pmin >= pmax pmin pmax print(pmin) print pmin break if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1 check(int((pmin+pmax)/2),n,w,k) check int((pmin+pmax)/2) int (pmin+pmax)/2 pmin+pmax pmin pmax 2 n w k pmax = int((pmin+pmax)/2) pmax int((pmin+pmax)/2) int (pmin+pmax)/2 pmin+pmax pmin pmax 2 pmin = int((pmin+pmax)/2)+1 pmin int((pmin+pmax)/2)+1 int((pmin+pmax)/2) int (pmin+pmax)/2 pmin+pmax pmin pmax 2 1 main() main def check(p, n, w, k):
	temp = 0
	for i in range(n):
		if w[i] > p:
			return False
		if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		temp += w[i]
	if k == 0:
		return False
	else:
		return True def check(p, n, w, k):
	temp = 0
	for i in range(n):
		if w[i] > p:
			return False
		if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		temp += w[i]
	if k == 0:
		return False
	else:
		return True check def main():
	n, k = map(int,input().split())
	w = []
	for _ in range(n):
		w += [int(input())]
	pmin = 0
	pmax = 10**10
	while True:
		if pmin >= pmax:
			print(pmin)
			break
		if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1 def main():
	n, k = map(int,input().split())
	w = []
	for _ in range(n):
		w += [int(input())]
	pmin = 0
	pmax = 10**10
	while True:
		if pmin >= pmax:
			print(pmin)
			break
		if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1 main
def check(p, n, w, k):
	temp = 0
	for i in range(n):
		if w[i] > p:
			return False
		if temp + w[i] > p:
			temp = 0
			k -= 1
			if k < 0:
				return False
		temp += w[i]
	if k == 0:
		return False
	else:
		return True

def main():
	n, k = map(int,input().split())
	w = []
	for _ in range(n):
		w += [int(input())]
	pmin = 0
	pmax = 10**10
	while True:
		if pmin >= pmax:
			print(pmin)
			break
		if check(int((pmin+pmax)/2),n,w,k):
			pmax = int((pmin+pmax)/2)
		else:
			pmin = int((pmin+pmax)/2)+1

main()
