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: Time Limit Exceeded

Solution code:
"""
AtCoder :: Beginner Contest 174 :: Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
"""
import sys
import math
import heapq


def main():
    """Main program."""
    log_count, cut_count = (int(i) for i in sys.stdin.readline().split())
    logs = [(-float(i), 0, float(i)) for i in sys.stdin.readline().split()]
    heapq.heapify(logs)
    for _ in range(cut_count):
        curr_length, cuts, init_length = heapq.heappop(logs)
        curr_length, cuts = -curr_length, -cuts
        cuts += 1
        curr_length = init_length / (cuts + 1)
        heapq.heappush(logs, (-curr_length, -cuts, init_length))
    print(math.ceil(-logs[0][0]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
        B = [int(ceil(a/arg))-1 for a in A]
        #print(arg, B)
        if sum(B) <= K:
            return True
        else:
            return False

    def meguru_bisect(ng, ok):
        '''
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng ok は  とり得る最小の値-1 とり得る最大の値+1
        最大最小が逆の場合はよしなにひっくり返す
        '''
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    ans = meguru_bisect(0, int(1e100))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N,K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

cut = [1]*N

for i in range(K):
    p = A.index(max(A))
    cut[p] += 1
    A[p] *= (cut[p]-1)/cut[p]

print(math.ceil(max(A)))

Submission status: Time Limit Exceeded

Solution code:
import copy
import math

N,K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

B = copy.deepcopy(A)
cut = [1]*N

for i in range(K):
    p = B.index(max(B))
    cut[p] += 1
    B[p] = A[p] / cut[p]

print(math.ceil(max(B)))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from bisect import insort_left
from collections import deque
from math import ceil

n, k = map(int, input().split())
a = [[i, 1] for i in map(int, input().split())]
A = sorted(a)
while k > 0:
    q, c = A.pop()
    insort_left(A, [q * c / (c + 1), c + 1])
    k -= 1
print(ceil(A[-1][0]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from bisect import insort_left
from collections import deque
from math import ceil

n, k = map(int, input().split())
a = [[i, 1] for i in map(int, input().split())]
A = deque(sorted(a))
while k > 0:
    q, c = A.pop()
    insort_left(A, [q * c / (c + 1), c + 1])
    k -= 1
print(ceil(A[-1][0]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
mc = np.zeros(len(a))
v = np.array( [i for i in a] ) + 0.0

#from numba import jit
#@jit
#def xxx():
while True:
	if k == 0:
		break
	mv_next = max( v / (mc + 2) )
	w = np.where( v > mv_next )[0]
	
	if len(w)>k:
		break
	k -= len(w)
	for x in w:
		mc[x] += 1
	#print(len(w))
v = v / (mc + 1)
while True:
	if k == 0:
		break
	mi = np.where( v == max(v) )[0][0]
	mc[mi] += 1
	v[mi] = a[mi] / (mc[mi]+1)
	k -= 1
import math
print(math.ceil(max(v)))

Submission status: Time Limit Exceeded

Solution code:

import numpy as np


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


N, K = acinput()
A = sorted(acinput(), reverse=True)


def bisect_search(f, val=0, l=0, r=10**6):

    # is_increase=(f(r)-f(l))>=0

    eps = 10**(-5)
    while True:

        c = (l+r)/2
        if f(c) == val:
            return c
        # if f(c)-val < eps:
        #    return c

        if f(c) < val:
            r = c

        else:
            l = c

        if l == r:
            return False


def f(d):
    n = 0
    i = 0
    while True:
        tmp = A[i]/d
        if tmp < 1:
            break
        n += np.ceil(tmp)-1
        i += 1
        if i >= len(A):
            break
    return n


res = bisect_search(f, K, l=0.01, r=A[0]+1)

if res == False:
    res = A[-1]
    print(res)
    sys.exit()

d = res
n = np.ceil(np.array(A)/d)


d2 = [0]*(N)
for i in range(N):
    d2[i] = A[i]/n[i]

print(int(np.ceil(max(d2))))

Submission status: Time Limit Exceeded

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

leq,high = 0,10**19
while high-leq > 1:
  l = (leq+high)//2
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)

Submission status: Time Limit Exceeded

Solution code:
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [int(ceil(a/pivot)) for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k
"""
if K >= 1000000:
    for i in range(N):
        h = hiritu[i]
        k = int(ceil(K*h/hirituSum))
        kaisu.append(k)
        K -= k
"""
leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print(ceil(l))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
num_arr = [1]*n
length_arr = [l for l in arr]

for i in range(k):
  max_idx = length_arr.index(max(length_arr))
  tmp = num_arr[max_idx] + 1
  num_arr[max_idx] = tmp
  length_arr[max_idx] = arr[max_idx] / tmp

result_int = max(length_arr) - 0.0001
print(int(result_int//1 + 1))

Submission status: Time Limit Exceeded

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

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

suki = 1000000000
kirai = 0
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		cnt += math.ceil(a[i] / targ)-1
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))

Submission status: Time Limit Exceeded

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

while(right-left>=1):
    numofcut=0
    
    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=max((left+right)//2,1)

print(mid)

Submission status: Time Limit Exceeded

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

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

suki = max(a)
kirai = 0
a.sort(key= lambda x: -x)
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		motome = math.ceil(a[i] / targ)-1
		if motome <= 0:
			break
		cnt += motome
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))

Submission status: Time Limit Exceeded

Solution code:
from numba import jit
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
mc = [0] * len(a)
import copy
v = [i+0.0 for i in a]
import math

@jit(nopython=True)
def solve(k,v,mc,a):
	for _ in range(k):
		mi = v.index(max(v))
		mc[mi] += 1
		v[mi] = (a[mi]+0.0) / (mc[mi]+1.0)
	return v
x = solve(k,v,mc,a)
print(math.ceil(max(x)))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

def f(x):
    return ([-float(x),-float(x),0])

n,k = map(int,input().split())
arr = list(map(f,input().split()))
#print(arr)
heapq.heapify(arr)
#print(arr)
for i in range(k):
    cur,org,cnt = heapq.heappop(arr)
    cur = org/(cnt+2)
    cnt+=1
    heapq.heappush(arr,[cur,org,cnt])
#print(arr)
print(math.ceil(heapq.heappop(arr)[0]*(-1.0)))

Submission status: Time Limit Exceeded

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

def leng(n, f):
    return (n-1)//f

logs = np.array(A)
vleng = np.vectorize(leng)

#めぐる式二分探索
def is_ok(i):
    if sum(vleng(logs, i)) <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, max(A) + 1))

Submission status: Time Limit Exceeded

Solution code:
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [a/pivot for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k

leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print(ceil(l))

Submission status: Time Limit Exceeded

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,-x)
        break

    y=-heapq.heappop(A)

    r=min(y,(x.a-1)//x.b)
    M=min(ceil((x*x.b)/r-x.b),K)
    

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

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

Submission status: Time Limit Exceeded

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

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

suki = max(a)
kirai = 0
a.sort(key= lambda x: -x)
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		motome = math.ceil(a[i] / targ)-1
		if motome <= 0:
			break
		cnt += math.ceil(a[i] / targ)-1
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))

Submission status: Time Limit Exceeded

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

def leng(n, f):
    return math.ceil(n / f) - 1

logs = np.array(A)
vleng = np.vectorize(leng)

#めぐる式二分探索
def is_ok(i):
    if sum(vleng(logs, i)) <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, max(A) + 1))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = [1 for i in range(N)]
t = [A[i] for i in range(N)]

for k in range(K):
    x = max(t)
    i = t.index(x)
    C[i] += 1
    t[i] = (A[i]+C[i]-1) // C[i]
print(max(t))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))
cut_num_arr = [1]*n
cut_length_arr = [l for l in arr]

for i in range(k):
  max_idx = np.argmax(cut_length_arr)
  tmp = cut_num_arr[max_idx] + 1
  cut_num_arr[max_idx] = tmp
  cut_length_arr[max_idx] = arr[max_idx] / tmp

print(math.ceil(max(cut_length_arr)))

Submission status: Time Limit Exceeded

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

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

suki = max(a)
kirai = 0
a.sort(key= lambda x: -x)
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		cnt += math.ceil(a[i] / targ)-1
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ
print(math.ceil(suki))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([float(x) for x in input().split()])
cut = [1]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]
print(math.ceil((max(chip))))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = [1 for i in range(N)]
t = [A[i] for i in range(N)]

for k in range(K):
    x = max(t)
    C[t.index(x)] += 1
    t[t.index(x)] = (A[t.index(x)]+C[t.index(x)]-1) // C[t.index(x)]
print(max(t))

Submission status: Time Limit Exceeded

Solution code:

import numpy as np


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


N, K = acinput()
A = sorted(acinput(), reverse=True)


def bisect_search(f, val=0, l=0, r=10**6):

    # is_increase=(f(r)-f(l))>=0

    eps = 10**(-5)
    while True:

        c = (l+r)/2
        if f(c) == val:
            return c
        # if f(c)-val < eps:
        #    return c

        if f(c) < val:
            r = c

        else:
            l = c

        if l == r:
            return False


def f(d):
    n = 0
    i = 0
    while True:
        tmp = A[i]/d
        if tmp < 1:
            break
        n += np.ceil(tmp)-1
        i += 1
        if i >= len(A):
            break
    return n


res = bisect_search(f, K, l=0.01, r=A[0]+1)

if res == False:
    res = A[-1]
    print(res)
    sys.exit()

d = res
n = np.ceil(np.array(A)/d)


d2 = []
for i in range(N):
    d2.append(A[i]/n[i])

print(int(np.ceil(max(d2))))

Submission status: Time Limit Exceeded

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

def isOK(L):
    num = 0
    for A in As:
        num += -(-A // L) - 1
    return num <= K

ng, ok = 0, 10**9
while abs(ok-ng) > 10**-6:
    mid = (ng+ok) / 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

k = int(-(-ok // 1))
#print('ok:', ok, '/ k:', k)

for L in range(max(1, k-2), k+3):
    if isOK(L):
        print(L)
        break

Submission status: Time Limit Exceeded

Solution code:
#from fractions import Fraction
from math import ceil
from heapq import heappush, heappop

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

A_queue = []
for a in input().split():
	a = float(a)
	heappush(A_queue, (-a, a, 1))

# search smallest i such that f(i) == True
def auto_bisearch_smallest(f, s = None):
	if s == None:
		s = 0
		w = -1
		while f(s) == True:
			s = w
			w *= 2
	e = s
	w = 1
	while f(e) == False:
		e = s + w
		w *= 2
	
	return bisearch_smallest(f, s, e + 1)

# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

def calc(K):
	while K > 0:
		length, a, div = heappop(A_queue)
		if len(A_queue) > 0:
			ref = A_queue[0][0]
			new_div = auto_bisearch_smallest(lambda div: -a / div > ref, div)
			K -= (new_div - div)
			heappush(A_queue, (-a / new_div, a, new_div))
		else:
			div += K
			K = 0
			heappush(A_queue, (-a / div, a, div))
	return -A_queue[0][0]

print(ceil(calc(K)))

Submission status: Time Limit Exceeded

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

def leng(n, f):
    ret = math.ceil(n / f) - 1
    if ret > 0:
        return math.ceil(n / f) - 1
    else:
        return 0

logs = np.array(A)
vleng = np.vectorize(leng)

#めぐる式二分探索
def is_ok(i):
    if sum(vleng(logs, i)) <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, 10 ** 9 + 1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([float(x) for x in input().split()])
cut = [1.0]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1.0
  chip[x]= Logs[x]/cut[x]
print(math.ceil((max(chip))))

Submission status: Time Limit Exceeded

Solution code:
"""
AtCoder :: Beginner Contest 174 :: Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
"""
import sys
import math
import heapq

class Log:
    def __init__(self, length):
        self.init_length = length
        self.curr_length = length
        self.cuts = 0

    def cut(self):
        self.cuts += 1
        self.curr_length = self.init_length / (self.cuts + 1)

    def __lt__(self, other):
        """Reversed, for heapq"""
        if self.curr_length == other.curr_length:
            return self.cuts > other.cuts
        else:
            return self.curr_length > other.curr_length


def main():
    """Main program."""
    log_count, cut_count = (int(i) for i in sys.stdin.readline().split())
    logs = [Log(float(i)) for i in sys.stdin.readline().split()]
    heapq.heapify(logs)
    for _ in range(cut_count):
        log = heapq.heappop(logs)
        log.cut()
        heapq.heappush(logs, log)
    print(math.ceil(logs[0].curr_length))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    import math
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    l,r=0,a[-1]
    while math.ceil(r)>math.ceil(l):
        x=(l+r)/2
        cnt=0
        for i in a:
            if i%x==0:
                cnt+=i//x-1
            else:
                cnt+=i//x
        if cnt>k:
            l=x
        else:
            r=x
    print(math.ceil(l))

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
X = [[a, 1] for a in A]

for _ in range(k):
    X.sort(key=lambda x: x[0]/x[1])
    X[-1][1] += 1

# print(X)

result = 0
for x in X:
    result = max(result, x[0]/x[1])

print(math.ceil(result))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = [1 for i in range(N)]

for k in range(K):
    t = [(A[i]+C[i]-1)//C[i] for i in range(N)]
    x = max(t)
    C[t.index(x)] += 1
t = [(A[i]+C[i]-1)//C[i] for i in range(N)]
print(max(t))

Submission status: Time Limit Exceeded

Solution code:
import math
from decimal import *
getcontext().prec = 10

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

def ok(x):
    cnt = 0
    n, m = x.as_integer_ratio()
    for a in A:
        if Decimal(a) <= x:
            break
        cnt += a * m // n
    return cnt <= K

ub = Decimal(A[0] + 1)
lb = Decimal(0)
for i in range(100):
    mid = (ub + lb) / 2;
    if ok(mid): ub = mid
    else: lb = mid

n, m = ub.as_integer_ratio()
ans = n // m + (n % m > 0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from math import ceil
from heapq import heappush, heappop

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

A_queue = []
for a in input().split():
	a = Fraction(int(a), 1)
	heappush(A_queue, (-a, a, 1))

# search smallest i such that f(i) == True
def auto_bisearch_smallest(f, s = None):
	if s == None:
		s = 0
		w = -1
		while f(s) == True:
			s = w
			w *= 2
	e = s
	w = 1
	while f(e) == False:
		e = s + w
		w *= 2
	
	return bisearch_smallest(f, s, e + 1)

# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

def calc(K):
	while K > 0:
		length, a, div = heappop(A_queue)
		if len(A_queue) > 0:
			ref = A_queue[0][0]
			new_div = auto_bisearch_smallest(lambda div: -a / div > ref, div)
			K -= (new_div - div)
			heappush(A_queue, (-a / new_div, a, new_div))
		else:
			div += K
			K = 0
			heappush(A_queue, (-a / div, a, div))
	return -A_queue[0][0]

print(ceil(calc(K)))

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline

from heapq import *

def solve():
    N, K = map(int, readline().split())
    A = list(map(int ,readline().split()))

    A.sort()

    B = [(-a, 1) for a in A]

    heapify(B)

    for i in range(K):
        b, n = heappop(B)
        heappush(B, (b * n / (n + 1), n + 1))

    ans = -min(B)[0]
    if ans != int(ans):
        print(int(1 + ans))
    else:
        print(ans)

solve()