Problem p02598 (python)

Fixed submission:
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm=0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm=0:
      mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)==(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:
    if um-lm<5:
        break

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:
    if um-lm<5:
        break

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(200):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,max(1,m-10),-1):
    if rf(mi)!=rf(mi-1):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(200):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,max(1,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(200):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
#    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
#    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m,m-10,-1):
#    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
#        return sum(a)
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,m)
    if um-lm<10:
        break
    elif rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
        um=m
        m=(lm+um)//2
    else:
        continue
#        print(m)
#        break

for mi in range(um,lm-1,-1):
#    print("mi:",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break
print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
#        return sum(a)
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,m)
    if um-lm<10:
        break
    elif rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
        um=m
        m=(lm+um)//2
    else:
        continue
#        print(m)
#        break

for mi in range(um,lm,-1):
#    print("mi:",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break
print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
#        return sum(a)
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#    print(ii,m)
    if um-lm<10:
        break
    elif rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
        um=m
        m=(lm+um)//2
    else:
        continue
#        print(m)
#        break

for mi in range(um,lm,-1):
#    print("mi:",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break
print(mi)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    if mm==0:
      mm=1
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(600):
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    else:
#        print(m)
        break

for mi in range(m,0,-1):
    if rf(mi)!=(n+k):
        break
print(mi+1)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(1000):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2+1
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
#    print(m,rf(m))
    if rf(m)>(n+k) :
        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2+1
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    else:
#        print(m)
        break

for mi in range(m,0,-1):
    if rf(mi)!=(n+k):
        break
print(mi+1)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#while True:
    print(m,rf(m))
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    else:
        print(m)
        break

for mi in range(m,0,-1):
    if rf(mi)!=(n+k):
        break
print(mi+1)