Problem p02598 (python)

Fixed submission:
import math
n,k = map(int,input().split())
alist = list(map(int,input().split()))

max_length = max(alist)
cur_length = 0

while(max_length - cur_length > 1):
    next_length = (max_length+cur_length)//2

    test_k = 0
    for i in range(n):
        test_k += math.ceil(alist[i]/next_length)-1

    if test_k <= k:
        max_length = next_length
    else:
        cur_length = next_length
        

print(max_length)

Buggy submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
alist = list(map(int,input().split()))

max_length = max(alist)
cur_length = 0

while(max_length - cur_length > 1):
    next_length = (max_length+cur_length)//2

    test_k = 0
    for i in range(n):
        test_k += math.ceil(alist[i]/next_length)-1

    if test_k <= k:
        max_length = next_length
    else:
        cur_length = next_length
        

if test_k > k:
    print(cur_length+1)
else:
    print(cur_length)

Buggy submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
alist = list(map(int,input().split()))

max = 0
for i in range(n):
    if max < alist[i]:
        max = alist[i]

max_length = max
cur_length = max_length//2

cuts = 0
for i in range(n):
    cuts += math.ceil(alist[i]/cur_length)-1

test_k = cuts
prev_length = 0
while(cur_length != prev_length):

    prev_length = cur_length
    cuts = 0
    if test_k <= k:
        max_length = cur_length
        cur_length = cur_length//2
    else:
        cur_length = (cur_length+max_length)//2
    if cur_length == 0:
        cur_length = 1
    for i in range(n):
        cuts += math.ceil(alist[i]/cur_length)-1
    test_k = cuts

if test_k > k:
    print(cur_length+1)
else:
    print(cur_length)

Buggy submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
alist = list(map(int,input().split()))

max = 0
for i in range(n):
    if max < alist[i]:
        max = alist[i]

max_length = max

cur_length = max_length//2

cuts = 0
for i in range(n):
    cuts += math.ceil(alist[i]/cur_length)-1

test_k = cuts
prev_length = 0
while(cur_length != prev_length):

    prev_length = cur_length
    cuts = 0
    if test_k <= k:
        max_length = cur_length
        cur_length = cur_length//2
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
    else:
        cur_length = (cur_length+max_length)//2
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
    test_k = cuts

if test_k > k:
    print(cur_length+1)
else:
    print(cur_length)

Buggy submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
alist = list(map(int,input().split()))

sum = 0
max = 0
for i in range(n):
    cur = alist[i]
    sum += cur
    if max < cur:
        max = cur

max_length = max

cur_length = sum//n

cuts = 0
for i in range(n):
    cuts += math.ceil(alist[i]/cur_length)-1

test_k = cuts
prev_length = 0
while(cur_length != prev_length):

    prev_length = cur_length
    if test_k <= k:
        max_length = cur_length
        cur_length = cur_length//2
        cuts = 0
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
        test_k = cuts
    else:
        cur_length = (cur_length+max_length)//2
        cuts = 0
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
        test_k = cuts

print(cur_length+1)