Problem:


Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192



Sample input:
2 3
7 9


Sample output:
4

Submission status: Runtime Error

Solution code:
#揃える長さを決め打って二分探索
import sys
import math
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst1.sort(reverse=True)
def func(mid): #ここが関数部分
    res = 0
    for i in range(n):
        if mid >= lst1[i]:
            continue
        res += math.ceil(lst1[i]/mid)-1
        if res > k:
            return False
    return True


def binary_search(): #2分探索
    ok = 10**9
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid):
            ok = mid
        else:
            ng = mid

    return ok


print(binary_search())

Submission status: Runtime Error

Solution code:
import math 
import bisect
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=(left+right)//2

while(right-left>=1):
    numofcut=0
    mid=(left+right)//2
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=A[i]//mid -1
        else:
            numofcut+=A[i]//mid
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    mid=(left+right)//2

print(mid)

Submission status: Runtime Error

Solution code:
import math

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))

def check(L):
    return sum(math.ceil(a / L)-1 for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if ok: 
        answer=min(m, answer)
        hi=m
    else:
        lo=m+1
print(answer))


"""
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo

    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo
"""

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=1
r=10**9
mid=0

if(K==0):
    print(max(A))
    sys.exit(0)

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    for i in range(len(A)):
        tmp+=A[i]//mid
    if(K<tmp):
        l=mid
    else:
        r=mid

tmp=0
for i in range(len(A)):
    tmp+=A[i]//l

tmp2=0
for i in range(len(A)):
    tmp2+=A[i]//(l-1)



if(tmp2<=K):
    print(l-1)
    sys.exit(0)

if(tmp<=K):
    print(l)
    sys.exit(0)

print(r)

Submission status: Runtime Error

Solution code:
from math import modf
n, k, *A = map(int, open(0).read().split())
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
c = k - sum(int(a/t)-1 for a in A)
X = []
for a in A:
    X.append(ceil(a / ceil(a/t)))
    X.append(ceil(a / int(a/t)))
X.sort()
print(X[-c-1])

Submission status: Runtime Error

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
a.sort()

if k==0:
    print(a[-1])
    exit()


# めぐる式二部探索
l=-1
r=a[-1]+1
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            x=-(-a[i]//mid)-1
            cnt-=x

    # なんらかの判定
    if cnt>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l = mid  # 判定がNGのとき→範囲を右に狭める

print(r)

Submission status: Runtime Error

Solution code:
import math 
import bisect
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=N//2
while(right-left>=1):
    numofcut=0
    mid=(left+right)//2
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=A[i]//mid -1
        else:
            numofcut+=A[i]//mid
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    

print(mid)

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=1
r=10**9
mid=0

if(K==0):
    print(max(A))
    sys.exit(0)

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    for i in range(len(A)):
        tmp+=A[i]//mid
    if(K<tmp):
        l=mid
    else:
        r=mid

tmp=0
for i in range(len(A)):
    tmp+=A[i]//l

tmp2=0
for i in range(len(A)):
    tmp2+=A[i]//r


if(tmp<=K):
    print(l)
    sys.exit(0)

 print(r)

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=1
r=10**9
mid=0

if(K==0):
    print(max(A))
    sys.exit(0)

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    for i in range(len(A)):
        tmp+=A[i]//mid
    if(K<tmp):
        l=mid
    else:
        r=mid

tmp=0
for i in range(len(A)):
    tmp+=A[i]//l

tmp2=0
for i in range(len(A)):
    tmp2+=A[i]//r


if(tmp<=K)
    print(l)
    sys.exit(0)
    
 print(r)

Submission status: Runtime Error

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
a.sort()

if k==0:
    print(a[-1])
    exit()


# めぐる式二部探索
l=-1
r=a[-1]+1
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            x=-(-a[i]//mid)
            cnt-=x

    # なんらかの判定
    if cnt>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l = mid  # 判定がNGのとき→範囲を右に狭める

print(r)

Submission status: Runtime Error

Solution code:
import heapq
from math import ceil,floor
import sys

class Fraction():
    ##入力定義
    def __init__(self,Numerator=0,Denominator=1):
        """分数のオブジェクトを生成する.

        Numerator:分子
        Denominator:分母
        """
        self.a=Numerator
        self.b=Denominator

    #表示定義
    def __str__(self):
        if self.b==1:
            return str(self.a)
        else:
            return "{}/{}".format(self.a,self.b)

    #四則演算定義
    def __add__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        return Fraction.__reduce(c)

    def __radd__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        
        return Fraction.__reduce(c)
    
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        return -self+other

    def __mul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __rmul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __floordiv__(self,other):
        if other==Fraction():
            raise ZeroDivisionError
        
        H=self/other
        return H.a//H.b

    def __rfloordiv__(self,other):
        if self==Fraction():
            raise ZeroDivisionError

        H=other/self
        return H.a//H.b
    
    def __truediv__(self,other):
        if other==Fraction():
            raise ZeroDivisionError
        
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return self*Fraction.__inverse(other)

    def __rtruediv__(self,other):
        if self==Fraction():
            raise ZeroDivisionError
        
        if not(isinstance(self,Fraction)):
            self=Fraction.Int_to_Fraction(other)
            
        return Fraction.__inverse(self)*other

    def __pow__(self,other):
        if other==0:
            return 1
        n=abs(other)

        g=1
        k=self
        for i in range(int(math.log(n,2))+1):
            if n%2==1:
                g*=k

            k*=k
            n=n>>1

        if other>0:
            return g
        else:
            return 1/g

    #丸め
    def __floor__(self):
        return self.a//self.b

    def __ceil__(self):
        return (self.a+self.b-1)//self.b
    
    #比較演算子
    def __eq__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a==0
        else:
            return t==0
    
    def __nq(self,other):
        return not(self==other)

    def __lt__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a<0
        else:
            return t<0

    def __le__(self,other):
        return (self<other) or (self==other)

    def __gt__(self,other):
        return -self<-other

    def __ge__(self,other):
        return (other<self) or (self==other)
    
    #その他
    def ToNumber(self):
        return self.a/self.b

    def sign(self):
        s=self.a*self.b
        if s>0:return 1
        elif s==0:return 0
        else:return -1

    def __reduce(self):
        from math import gcd
        g=gcd(self.a,self.b)
        self.a//=g
        self.b//=g

        if self.b<0:
            self.a*=-1
            self.b*=-1
        return Fraction(self.a,self.b)

    def Int_to_Fraction(self):
        if not(isinstance(self,Fraction)):
            return Fraction(self,1)
        else:return self
        
    def __inverse(self):
        if self==Fraction():
            raise ZeroDivisionError
        
        return Fraction.__reduce(Fraction(self.b,self.a))
    
    def __pos__(self):
        return self

    def __neg__(self):
        return Fraction(-self.a,self.b)

    def __abs__(self):
        return max(self,-self)
#=======================================
N,K=map(int,input().split())
A=list(map(lambda x:-Fraction(int(x),1),input().split()))

if N==1:
    print((-A[0]+K)//(K+1))
    sys.exit()
    
heapq.heapify(A)
while K>0:
    x=-heapq.heappop(A)

    if x<=1:
        heapq.heappush(A,-a)
        break

    J=floor(x)
    M=min(max(ceil(x.a/J-x.b),1),K)

    x.b+=M
    K-=M
    heapq.heappush(A,-x)   
    

b=-A[0]
b=ceil(b)
print(b)

Submission status: Runtime Error

Solution code:
#from functools import lru_cache
import sys
import math
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

ls = rvfunc(int)(reader())
n,k=ls[0]
a=ls[1]

def reqk(num):
    return sum(vfunc(lambda aa:math.ceil(aa/float(num))-1)(a))
def binary_search(imin=None,imax=None):
    if [imin,imax]==[None]*2: imin,imax=0,10**9
    if (imax < imin):
        return imin
    else:
        imid = int(imin + (imax - imin) / 2)
        if (reqk(imid)<k):return binary_search(imin, imid - 1)
        elif (reqk(imid)>k):return binary_search(imid + 1, imax)
        else:return imid
print(binary_search() if k!=0 else max(a))

Submission status: Runtime Error

Solution code:
from math import modf
n, k, *A = map(int, open(0).read().split())
A.sort(reverse=1)
t = sum(A) / (n+k)
B = [(modf(a/t - 1)[0], modf(a/t - 1)[1], a) for a in A if a/t > 1]
B.sort(reverse=1)
c = k - sum(int(y) for x, y, z in B)
ans = 0
X = []
for i, (_, y, z) in enumerate(B):
    X.append(ceil(z / (y+2)))
    X.append(ceil(z / (y+1)))
X.sort()
print(X[-c-1])

Submission status: Runtime Error

Solution code:
import math

n,k = map(int,input().split())
logs = list(map(int, input().split()))
total =  0
for i in range(n):
    total += logs[i]
kari = total // k + 1

for j in range(k):
    lo = max(logs)
    logs.remove(lo)
    if lo > kari:
        lo_s = lo-kari
        logs.append(kari)
        logs.append(lo_s)
    else:
        lo_s = lo/2
        logs.append(lo_s)
        logs.append(lo_s)

ans = math.ceil(max(logs))
print(ans)

Submission status: Runtime Error

Solution code:
import heapq
import math


#
class Value:
    def __init__(self, v):
        self.v = v
        self.s = 1
        self.value = self.v

    def ups(self, s):
        self.s += s
        self.value = self.v / self.s

    def __lt__(self, other):
        return self.value > other.value


def _run(N, K, As):
    a = []
    for i, v in enumerate(As):
        a.append(Value(v))
    heapq.heapify(a)

    try_c = 0
    while try_c < K:
        v1 = heapq.heappop(a)
        v2 = heapq.heappop(a)
        cc = math.ceil(v1.value / v2.value)
        cc = min(K - try_c - cc, cc)
        if cc == 0:
            break
        v1.ups(cc)
        heapq.heappush(a, v1)
        heapq.heappush(a, v2)
        try_c += cc

    print(math.ceil(heapq.heappop(a).value))


def _main():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))
    _run(N, K, As)


if __name__ == "__main__":
    _main()

Submission status: Runtime Error

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
a.sort()

if k==0:
    print(a[-1])
    exit()


# めぐる式二部探索
l=-1
r=pow(10,11)
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            x=a[i]//mid
            cnt-=x

    # なんらかの判定
    if cnt>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l = mid  # 判定がNGのとき→範囲を右に狭める

print(r)

Submission status: Runtime Error

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=sum(a)
ideal=math.ceil(l/(k+n))
count=0
for i in range(n):
    count+=a[i]//ideal
    a[i]=a[i]%ideal
if x > ideal for x in a:
    print(ideal+1)

Submission status: Runtime Error

Solution code:
import math
N,K=map(int, input().split())
AA=sorted(list(map(int,input().split())))
BB=[0]*N
for i in range(N):
    BB[i]=math.log2(AA[i])
for i in range(K):
    BB[-1]=BB[-1]-1
    BB=sorted(BB)
print(math.floor(2^BB[-1]))

Submission status: Runtime Error

Solution code:
import math
import heapq
n,k = map(int,input().split())
lis = list(map(int,input().split()))
nu = 0
li = []
for i in range(n):
    num = lis[i]
    nu += math.log(num)
    li.append([math.log(num),num,0])

for i in range(n):
    li[i][0] = (li[i][0] * k)/nu
li.sort(reverse=True)

for i in range(n):
    li[i][2] = math.floor(li[i][0])
    li[i][0] -= li[i][2]
    k -= li[i][2]

li.sort(reverse=True)
for i in range(k):
    li[i][2] += 1
ans = 0
for i in range(n):
    ans = max(ans,math.ceil(li[i][1]/(li[i][2]+1)))
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))

def check(L):
    return sum(a // L for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if not ok: # 
        lo=m+1
    else:
        answer=min(m, answer)
        hi=m
print(answer))


"""
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo

    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo
"""

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(n):
    a[i]=[a[i],i]
for i in range(1,23):
    if 2**i>=n:
        num=i
        break
num2=2**(num-1)
ans=num2
ans2=0
for i in range(num):
    num3=0
    num4=a[ans-1][0]
    for j in range(ans,n):
        num3+=-(a[j][0]//-num4)-1
    num2=num2//2
    if num4>=k:
        ans=max(ans-num2,1)
        ans2=num3
    else:
        ans=min(ans+num2,n-1)
k-=ans2
num5=a[ans-1][0]
ans3=[0]*n
for i in range(ans,n):
    num6=-(a[i][0]//-num5)
    a[i][0]=a[i][0]/num6
    ans3[i]=num6
a.sort()
for i in range(k):
    ans3[a[-1][1]]+=1
    a[-1]/=ans3[a[-1][1]]
    a.sort()
print(-(a[-1][0])//-1)

Submission status: Runtime Error

Solution code:
import numpy
N, K = map(int, input().split())
A = numpy.array(list(map(int, input().split())))

A = numpy.log2(A)

# for i in range(5):
while True:
    A = numpy.sort(A)
    C = 2 ** numpy.floor(A[-1] - A[-2])
    C = min(C, K)

    if C == 0:
        break

    A[-1] += -C
    K += -C

B = 2 ** A
ans = numpy.max(B)
print(int(ans))

Submission status: Runtime Error

Solution code:
N, K=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
for _ in range(K):
    print(A)
    l=A.pop(len(A)-1)/2
    print(A)
    i=-1
    j=len(A)-1
    while i<=j:
        print(i,j)
        k=(i+j)//2
        print(k)
        if k==-1:
            A.insert(0, l)
            break
        elif k==len(A)-1:
            A.insert(l)
            break
        elif A[k]<=l and A[k+1]>=l:
            A.insert(k, l)
            A.insert(k, l)
            break
        elif A[k]>l:
            j=k-1
        else:
            i=k+1
print(math.ceil(A[len(A-1)]))

Submission status: Runtime Error

Solution code:
nk=input("").split(" ")
n=int(nk[0])
k=int(nk[1])
lia=input("").split(" ")
lisa=[]
for i in lia:
    lisa+=[int(i)*10000]
sa=sum(lisa)
lisf=[]
lisw=[]
t=int(sa/(k+1))

for i in lisa:
    f=i%t
    ffff=(i*(k+1))%sa
    
    if(ffff==0):
        lisf+=[0]
        lisw+=[int(i*(k+1)/sa)-1]
    else:
        lisf+=[(sa/(k+1)-f)/(int(i*(k+1)/sa)+1)]
        lisw+=[int(i*(k+1)/sa)]

lisf.sort()
s=k-sum(lisw)

kk=int((t-lisf[s])/10000)
if(((sa/(k+1)-lisf[s])%10000)==0):
    print(kk)
else:
    print(kk+1)

Submission status: Runtime Error

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=sorted(lmp())
ans=10**10
l=1
r=a[-1]
while True:
    if x==l and y==r:
        print(r)
        exit()
    m=(l+r)//2
    c=0
    for i in a:
        c+=-(-i//m)-1
    if c>k:
        l=m
    else:
        r=m

Submission status: Runtime Error

Solution code:
#200510E
import math
N, K = map(int, input().split())
A = list(map(int,input().split()))
L = len(A)
count = 0
B = sorted(A)
ans = B[L-1]

while count < K:
    B = sorted(B)
    X = B[L-1]
    if B[L-1]//B[L-2] < 2:
        B.remove(X)
        B.append(X/2)
        B.append(X/2)
        count +=1
        L += 1
        B = sorted(B)
        ans = B[L-1]
        
    else:
        if B[L-1]//B[L-2] > K-count:
            ans = X // (K-count)
            break
        else:
            N = B[L-1]//B[L-2]
            B.remove(X)
            for i in range(N):
                B.append(X/N)
                count +=1
                L += 1
            B = sorted(B)
            ans = B[L-1]
ans = math.ceil(ans)

print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if int(ans)==int(mid):
                flag=True
        ans=min(ans, mid)
        right=mid
        
        if flag:
            break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, mid)
        right=mid
        pre=mid
    count+=1
    if count>=10**6:
        
        
if ans==float("INF"):
    ans=max(A)
print(ceil(ans))

Submission status: Runtime Error

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return x

def int_map():
    return map(float,input().split())

def int_list():
    return list(map(int,input().split()))

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np
from collections import Counter
from math import ceil

# main code
N,K = int_map()
A = int_list()

c = Counter(A)

lo = sorted(list(c.keys()),reverse=True)

now = lo.pop(0)
num = c.pop(now)
K = K-num

if K <= 0:
    print(ceil(max(now/2,lo[0])))
    exit()

l1 = [now/2]
c[now/2] = c[now/2] + 2*num

while True:
    if len(l1) > 0 and len(lo) > 0:
        if lo[0] >= l1[0]:
            now = lo.pop(0)
        else:
            now = l1.pop(0)
    elif len(lo) >0:
        now = lo.pop(0)
    else:
        now = l1.pop(0)

    num = c.pop(now)

    K = K-num
    l1.append(now/2)

    if K <= 0:
        if len(lo) > 0 and len(l1) > 0:
            print(ceil(max(max(now/2,lo[0]),l1[0])))
        elif len(lo) == 0:
            print(ceil(max(now/2,l1[0])))
        else:
            print(ceil(max(now/2,lo[0])))
        exit()

    c[now/2] = c[now/2] + 2*num

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

def f(x):
    ret = 0
    for a in A:
        ret += a//x
    return ret

if K == 0:
    print(max(A))
    exit()
ok = -1
ng = 10**9 + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid) <= K:
        ng = mid
    else:
        ok = mid
print(ng)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
aa=sum(a)/(k+n)
ans=[1]
ans*=n
for i in range(n):
    if a[i]//aa>=1:
        ans[i]=a[i]//aa
aaa=k+n-sum(ans)
for i in range(n):
    a[i]/=ans[i]
a.sort(reverse=True)
aaa=int(aaa)
if a[aaa]>int(a[aaa]):
    a[aaa]+=1
print(int(a[aaa]))

Submission status: Runtime Error

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
a.sort()

if k==0:
    print(a[-1])
    exit()


# めぐる式二部探索
l=-1
r=pow(10,11)
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            cnt-=a[i]//mid

    # なんらかの判定
    if cnt>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l = mid  # 判定がNGのとき→範囲を右に狭める

print(r)

Submission status: Runtime Error

Solution code:
def main():
    from collections import deque,defaultdict
    import heapq
    import math
    n,k = map(int,input().split())
    A = list(map(int,input().split()))
    A = list(map(lambda x: x*(-1), A)) 
    A.sort()
    # print(A)
    heapq.heapify(A)
    C = defaultdict(int)
    MAP = dict(zip(A,A))
    # print(MAP)

    c = 0
    while True:
        if c == k:
            break

        a = heapq.heappop(A)*(-1)
        # print(a)
        b = MAP[a*(-1)]
        C[b] += 1
        MAP.pop(a*(-1))
        a = math.ceil(b*(-1)/(C[b]+1))
        # a = b//-(C[b]+1)
        # print(a)
        MAP[a*(-1)] = b
        heapq.heappush(A,a*(-1))
        c += 1
        # print(A)

    A.sort()
    print(A[0]*(-1))
    # print(C)

        
main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import heapq

N, K = map(int, input().split())
a = map(int, input().split())

log_dict = defaultdict(int)
log_list = []
for i in a:
    log[i] += 1
    if -i not in log_list:
        log_list.append(-i)
        
heapq.heapify(log_list)


while True:
    l = heapq.heappop(log_list)
    if K > log_dict[l]:
        K -= log_dict[l]
        log_dict[l//2] += log_dict[l] * 2
        log_dict[l] = 0
        if l//2 not in log_list:
            heapq.heappush(log_list, l//2)

    else:
        print(int(log_dict/(K+1)))
        exit()

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
a=np.sort(a)
if k==0:
  print(np.max(a))
  exit()
sa=np.sum(a)
one=sa//(n+k-1)
b=a/one
b=np.round(b)
sb=np.sum(b)
ak=sb/k
c=np.round(b/ak)
#print(c)
sc=np.sum(c)
if sc==k:
  d=c+1
  e=a/d
  #print(e)
  print(math.ceil(np.max(e)))
else:
  f=b//ak
  sf=np.sum(f)
  if sf==k:
    d=f+1
    e=a/d
    #print(e)
    print(math.ceil(np.max(e)))
  else:
    cha=int(k-sc)
    #print(cha)
    for i in range(cha):
      c[-i]=c[-i]+1
    d=c+1
    e=a/d
    print(math.ceil(np.max(e)))
    
  
    #print(c)

Submission status: Runtime Error

Solution code:
import math 
import bisect
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=N//2
while(right-left>=0):
    numofcut=0
    mid=(left+right)//2
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=A[i]//mid -1
        else:
            numofcut+=A[i]//mid
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid-1
    

print(mid)

Submission status: Runtime Error

Solution code:
import math
n,k = map(int, input().split(' '))
a_s= list(map(int, input().split(' ')))

tot=0
for log in a_s:
	tot+= log
table={}

ans= 0


for log2 in a_s:
	test= math.ceil(log2/ ((math.ceil(log2/tot*k))))
	if test>ans:
		ans=test
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))

def check(L):
    return sum(a // L for a in A) <= K

answer=max(A)
lo = 0
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if not ok: # 
        lo=m+1
    else:
        answer=m
        hi=m
print(min(max(A), answer))


"""
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo

    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo
"""

Submission status: Runtime Error

Solution code:
import heapq, math, sys

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
maxA = A[0]
pre = -1
while len(A) != pre:
    if len(A) == 0:
        print(math.ceil(maxA))
        sys.exit()
    pre = len(A)
    meanA = math.ceil(sum(A)/(len(A)+K))
    for i, a in enumerate(A):
        if a <= meanA:
            A = A[:i]
            break


cuts = [0]*(i+1)
meanA = math.ceil(sum(A)/(len(A)+K))
for i, a in enumerate(A):
    cut_at_least = (a//meanA - 1)
    cuts[i] = cut_at_least
    K -= cut_at_least
hq = [(-a/(cut+1), i) for i, (a, cut) in enumerate(zip(A, cuts))]
heapq.heapify(hq)
lenhq = len(hq)
if K>N:
    raise ValueError
for k in range(K):
    l, i = heapq.heappop(hq)
    cuts[i] += 1
    heapq.heappush(hq, (-A[i]/(cuts[i]+1), i))
l, i = heapq.heappop(hq)
print(math.ceil(-l))

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())

a=input().split()
A=[int(b) for b in a]

whole=sum(A)

n_A=sorted(A,reverse=True)



answers=[]
for a in n_A:
    answers.append(round(a*K/whole))

if K==0:
    print(n_A[0])
else:
    print(max(math.ceil(n_A[0]/(answers[0]+1)),math.ceil(n_A[1]/(answers[1]+1))))

Submission status: Runtime Error

Solution code:
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from heapq import heapify, heappop, heappush
# from math import sqrt
from math import ceil, log, floor
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, k = sp()
arr = L()
low, high = 0, max(arr)
answer = max(arr)
while low <= high:
    mid = (low + high) >> 1
    req = 0
    for i in range(n):
        if arr[i] <= mid:
            continue
        else:
            temp = arr[i] // mid
            req += temp
    if req <= k:
        answer = min(answer, mid)
        high = mid - 1
    else:
        low = mid + 1
out(answer)