Buggy python submission (verdict: Time Limit Exceeded):

def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt:
				return False
		else:
			cur += w	
	return True

n, k = map(int, input().split())
weights = [0] * n
cpct = 0
for i in range(n):
	weight = int(input())
	weights[i] = weight
	cpct = max(cpct, weight)
	
while True:	
	can_alloc = check_alloc(weights, k, cpct)
	if can_alloc == False:
		cpct += 1
	else:
		break

print(cpct)



Fixed submission:
import sys

def check_alloc(weights, k, cpct):
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > k or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
sum = 0
maxi = 0
for i in range(n):
	w = int(input())
	weights[i] = w
	sum += w
	maxi = max(maxi, w)

if k == 1:
	print(sum)
	sys.exit()

start = maxi
end = sum
cpct = 0
while start <= end:
	cpct = int(start + (end - start) / 2)
	check = check_alloc(weights, k, cpct)
	if check == False:
		start = cpct + 1
	else:
		if start == end: break
		end = cpct
	
print(cpct)

Buggy python submission (verdict: Time Limit Exceeded):

def check_alloc(weights, cnt, cpct):	
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
cpct = 0
for i in range(n):
	weight = int(input())
	weights[i] = weight
	cpct += weight

cpct = int(cpct/k)
while True:	
	can_alloc = check_alloc(weights, k, cpct)
	if can_alloc == False:
		cpct += 1
	else:
		break

print(cpct)



Fixed submission:
import sys

def check_alloc(weights, k, cpct):
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > k or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
sum = 0
maxi = 0
for i in range(n):
	w = int(input())
	weights[i] = w
	sum += w
	maxi = max(maxi, w)

if k == 1:
	print(sum)
	sys.exit()

start = maxi
end = sum
cpct = 0
while start <= end:
	cpct = int(start + (end - start) / 2)
	check = check_alloc(weights, k, cpct)
	if check == False:
		start = cpct + 1
	else:
		if start == end: break
		end = cpct
	
print(cpct)

Buggy python submission (verdict: Time Limit Exceeded):

def check_alloc(weights, cnt, cpct, st, stn):	
	num = 1
	cur = stn
	for i in range(st, len(weights)):
		w = weights[i]
		if cur + w > cpct:
			if num == 1:
				st = i
				stn = cur
			cur = w
			num += 1
			if num > cnt or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
cpct = 0
for i in range(n):
	weight = int(input())
	weights[i] = weight
	cpct += weight

cpct = int(cpct/k)
st = 0
stn = 0
while True:
	can_alloc = check_alloc(weights, k, cpct, st, stn)
	if can_alloc == False:
		cpct += 1
	else:
		break

print(cpct)



Fixed submission:
import sys

def check_alloc(weights, k, cpct):
	num = 1
	cur = 0
	for i in range(len(weights)):
		w = weights[i]
		if cur + w > cpct:
			cur = w
			num += 1
			if num > k or cur > cpct:
				return False
		else:
			cur += w
	return True

n, k = map(int, input().split())
weights = [0] * n
sum = 0
maxi = 0
for i in range(n):
	w = int(input())
	weights[i] = w
	sum += w
	maxi = max(maxi, w)

if k == 1:
	print(sum)
	sys.exit()

start = maxi
end = sum
cpct = 0
while start <= end:
	cpct = int(start + (end - start) / 2)
	check = check_alloc(weights, k, cpct)
	if check == False:
		start = cpct + 1
	else:
		if start == end: break
		end = cpct
	
print(cpct)