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:
import heapq
from math import ceil
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)
    M=min(ceil(x.a/(x.a//x.b)-x.b),K,1)
    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()))
A.sort(reverse=True)
s=A[0]
e=A[N-1]
k=(s+e)/2
while(1):
    count=0
    for i in range(N):
        count+=math.ceil(A[i]/k)
    if(count==(N+K)):
        break
    if(count>(N+K)):
        k=(s+k)/2
    else:
        k=(k+e)/2
ma=0
for i in range(N):
    A[i]=math.ceil(A[i]/math.ceil(A[i]/k))
    if(ma<A[i]):
        ma=A[i]
print(ma)

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(1000000001)
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:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
ans = 0
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

C = sum(cut)
res = K - C
length = length[:res+1]
for k in range(res):
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
  for k in range(1, len(length)):
    if length[0][0] > length[k][0]:
      length = length[1:k] + [length[0]] +length[k:]
      break
  else:
    length = length[1:]
print(math.ceil(length[0][0]))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from fractions import Fraction
from sys import exit
import heapq

n,k, *aa = map(Fraction, open(0).read().split())

left = k/2
right = k*2 + 1
mid = k/2
summ = sum(aa)
score = None
while 1:
    x = [(ceil(mid*a/summ), a) for a in aa]
    prev = score
    score = sum(a[0]-1 for a in x)
    if prev == score:
        break
    if score > k:
        right = mid
        mid = (left + right) / 2
    elif score < k:
        left = mid
        mid = (left + right) / 2
    else:
        values = [ceil(a/v) for v,a in x]
        print(max(values))
        exit()

x = [(-a/c, c, a) for c,a in x]
heapq.heapify(x)

for _ in range(int(k-score)):
    v,c,a = heapq.heappop(x)
    c += 1
    v = -a/c
    heapq.heappush(x, (v,c,a))

print(ceil(-x[0][0]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import math

numbers = input().split(" ")
n = int(numbers[0])
k = int(numbers[1])

numbers = input().split(" ")

a1 = [int(x) for x in numbers]
a2 = [x for x in a1]
a3 = [0] * n

#a2.sort(key=lambda x: x[1])

for i in range(k):
    index = a2.index(max(a2))
    a2[index] /= 2
    a3[index] += 1


for i in range(n):
    a1[i] /= (a3[i] + 1)


index = a1.index(max(a1))
print(math.ceil(a1[index]))

Submission status: Time Limit Exceeded

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
a = lr()

def getK(num):
    ret = 0
    for tmp in a:
        while tmp > num:
            tmp = tmp/2
            ret+=1
    return ret

ans = 0
l = 0
r = max(a)
while l <= r:
    mid = l + (r-l) / 2
    if getK(mid) < k:
        r = mid
    else:
        l = mid+1
    if l > r:
        ans = mid
        break
print(math.ceil(ans))

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()))

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

ub = Decimal(1000000001)
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:
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return(a//b)+1
N,M=map(int,input().split())
L2=list(map(int,input().split()))
L=[i for i in L2]
R=[1]*N
for i in range(M):
  R[L.index(max(L))]+=1
  c=zip(L2,R)
  L=[waru(x,y) for (x,y) in c]
print(max(L))

Submission status: Time Limit Exceeded

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


def main():
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    c = [1] * n
    h = []
    for i, ai in enumerate(a):
        heappush(h, (-ai, i))
    for _ in range(k):
        ai, i = heappop(h)
        ci = c[i]
        ai = ai * ci / (ci + 1)
        heappush(h, (ai, i))
        c[i] += 1
    print(ceil(-h[0][0]))


if __name__ == '__main__':
    main()

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, 10 ** 9 + 1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
n, k = map(int, input().split()) # n本, k回
lenorg = list(map(int, input().split()))
lentotal = sum(lenorg)
ave = lentotal / (k+n)
cnt = [max(0,int((l // ave) -1)) for l in lenorg]
cnttmp = sum(cnt)
m = k - cnttmp
lenorg = np.array(lenorg)
cnt = np.array(cnt)
lentmp = lenorg / (cnt+1)
for i in range(m):
    tar = np.argmax(lentmp)
    cnt[tar] += 1
    lentmp[tar] = lenorg[tar] / (cnt[tar]+1)
print(int(np.ceil(max(lentmp))))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

length_heap = []

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

length_list = list(map(int, input().split()))
for index, l in enumerate(length_list):
    heapq.heappush(length_heap, (-l, 1, index))

for i in range(total_cut):
    longest, cut_n, idx = heapq.heappop(length_heap)
    heapq.heappush(length_heap, (-length_list[idx]/(cut_n+1), (cut_n + 1), idx))

result = -heapq.heappop(length_heap)[0]

print(math.ceil(result))

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))

def calc(K):
	while K > 0:
		length, a, div = heappop(A_queue)
		div += 1
		K -= 1
		heappush(A_queue, (-a / div, a, div))
	return -A_queue[0][0]

print(ceil(calc(K)))

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]
    kaisu.append(int(K*(h/hirituSum)))
    K -= int(K*(h/hirituSum))
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
n,k = map(int,input().split())
a = list(map(int,input().split()))

c = [1]*n
b = []
for i in range(n):
    b.append([-a[i],i])

heapq.heapify(b)
b.sort()
for i in range(k):
    x,ind = heapq.heappop(b)
    c[ind] += 1
    heapq.heappush(b,[-a[ind]/c[ind],ind])

ans = 0

for i in range(n):
    ans = max(-(-a[i]//c[i]),ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

cut = [1] *n
r = []
for i in a:
    r.append(i)

for i in range(k):
    max_n = 0
    max_i = -1
    for i in range(n):
        if max_n < r[i]:
            max_n = r[i]
            max_i = i
    cut[max_i] += 1
    r[max_i] = a[max_i] / cut[max_i]

print(math.ceil(max(r)))

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))

def calc(K):
	while K > 0:
		length, a, div = heappop(A_queue)
		div += 1
		K -= 1
		heappush(A_queue, (-a / div, a, div))
	return -A_queue[0][0]

print(ceil(calc(K)))

Submission status: Time Limit Exceeded

Solution code:
import math

n , k = map(int, input().split())
a = list(map(int,input().split()))
b = [1]*n

for i in range(k):
    t = a.index(max(a))
    a[t]=a[t]*b[t]/(b[t]+1)
    b[t]+=1

print(math.ceil(max(a)))

Submission status: Time Limit Exceeded

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

  for i in range(n):
    a[i] = [(-1) * a[i], (-1) * a[i], 1]

  import heapq
  heapq.heapify(a)

  for _ in range(k):
    i = heapq.heappop(a)
    i[2] += 1
    i[0] = i[1] / i[2]
    heapq.heappush(a, i)

  from math import ceil
  print(ceil((-1) * heapq.heappop(a)[0]))

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import Fraction
import math
import heapq
input = sys.stdin.readline

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

s = sum(a)

w = [(k * a[i]) // s for i in range(n)]
b = [Fraction((w[i] + 1), a[i]) for i in range(n)]

r = k - sum(w)

heapq.heapify(b)
#print(b)

for i in range(r):
    x = heapq.heappop(b)
    heapq.heappush(b, Fraction(x.numerator+1, x.denominator))

y = heapq.heappop(b)

print(math.ceil(Fraction(y.denominator, y.numerator)))

Submission status: Time Limit Exceeded

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

Solution code:
import heapq
import math
import sys

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for i in range(N):
        p = A[i]
        A[i] = [-p, i]

    heapq.heapify(A)
    C = [0]*N
    for j in range(K):
        x, y = heapq.heappop(A)
        cnt = C[y]
        x = x * (cnt+1) / (cnt+2)
        C[y] += 1
        heapq.heappush(A, [x, y])

    ans = heapq.heappop(A)[0]

    ans = math.ceil(-ans)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heapreplace, heappop
from math import ceil

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

A = list(map(int, input().split()))


hq = []
for a in A:
    heappush(hq, (-a, 1, a))
    # 現在の長さ　カット数　元の長さ

for _ in range(K):
    _, c, l = hq[0]
    heapreplace(hq, (-l/(c+1), c+1, l))

max_length, _, _ = heappop(hq)
print(ceil(-max_length))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import math

numbers = input().split(" ")
n = int(numbers[0])
k = int(numbers[1])

numbers = input().split(" ")

a1 = [int(x) for x in numbers]
a2 = [[i, a1[i], 0] for i in range(n)]

#a2.sort(key=lambda x: x[1])

for i in range(k):
    a2.sort(key=lambda x: x[1])
    a2[-1][1] /= 2
    a2[-1][2] += 1

a2.sort(key=lambda x: x[0])

for i in range(n):
    a1[i] /= (a2[i][2] + 1)

a1.sort()

print(math.ceil(a1[-1]))

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
import math

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

Z = []
for i in range(N):
    ver = [A[i], 0]
    Z.append(ver)

for k in range(K):
    h = Z.index(max(Z))
    Z[h][1] += 1
    Z[h][0] /= 2 

for j in range(N):
    A[j] = A[j]/(Z[j][1]+1)

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

sum_a = sum(a)
min_l = sum_a / (n+k)
max_l = min_l * 1.5
l = min_l
cnt = 0
ls_l = [0 for _ in range(n)]
ls_ll = [0 for _ in range(n)]
ls_div = [0 for _ in range(n)]
#print("min")
#print(min_l)

for i,aa in enumerate(a):
  if aa % min_l < min_l/2:
    div = aa // min_l - 1
  else:
    div = aa // min_l
  if div < 1:
    ls_l[i] = aa
    ls_ll[i] = 0
    ls_div[i] = 1
  else:
    ls_l[i] = aa / div
    ls_ll[i] = aa / div
    ls_div[i] = int(div)

#print(ls_l)
#print(ls_div)
#print(sum(ls_div))

s = sum(ls_div)

for _ in range(n+k - s):
  max_i = ls_ll.index(max(ls_ll))
  ls_div[max_i] += 1
  ls_ll[max_i] = a[max_i] / ls_div[max_i]
  ls_l[max_i] = a[max_i] / ls_div[max_i]
  #print("ls_ll: {}".format(ls_ll))
  
#print(max(ls_l))
print(math.ceil(max(ls_l)))

Submission status: Time Limit Exceeded

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):
        self.s += 1
        self.value = self.v / self.s

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


def _run(N, K, As):
    a = []
    for v in As:
        a.append(Value(v))
        # heapq.heappush(a, Value(v))
    heapq.heapify(a)
    for _ in range(K):
        v = heapq.heappop(a)
        v.ups()
        heapq.heappush(a, v)
    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: Time Limit Exceeded

Solution code:
import math
import heapq
n,k = map(int,input().split())
lis = list(map(int,input().split()))
li = [[-num,1] for num in lis]
heapq.heapify(li)
  # print(li)
for i in range(k):
    a = heapq.heappop(li)
    heapq.heappush(li,[(a[0]*a[1])/(a[1]+1),a[1]+1])
  #     print(li)
print(math.ceil(-li[0][0]))

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

hq = []

for i in range(n):
    a[i] = -a[i]

for i in range(n):
    heapq.heappush(hq,[a[i],i,1])

for i in range(k):
    val,idx,waru = heapq.heappop(hq)
    heapq.heappush(hq, [a[idx]/(waru+1),idx,waru+1])
    #print(hq)
    
val,idx,waru = heapq.heappop(hq)

if val % 1 == 0:
    print(int(val)*(-1))
else:
    print(int(val)*(-1)+1)

Submission status: Time Limit Exceeded

Solution code:
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=A.copy()
warulist=[1]*N
for i in range(K):
    Amax=max(a)
    Amaxindex=a.index(Amax)
    warulist[Amaxindex]+=1
    a[Amaxindex]=A[Amaxindex]/warulist[Amaxindex]
print(math.ceil(max(a)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import math

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

b = a[:]
vote = [0] * n
ans = 0
for i in range(k):
    tar = b.index(max(b))
    vote[tar] += 1
    b[tar] = a[tar] / (vote[tar] + 1)

print("{}".format(int(math.ceil(max(b)))))

Submission status: Time Limit Exceeded

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

for i in range(n):
  a[i] = [(-1) * a[i], (-1) * a[i], 1]

import heapq
heapq.heapify(a)

for _ in range(k):
  i = heapq.heappop(a)
  i[2] += 1
  i[0] = i[1] / i[2]
  heapq.heappush(a, i)

from math import ceil
print(ceil((-1) * heapq.heappop(a)[0]))

Submission status: Time Limit Exceeded

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

cut = [1] *n
r = []
for i in a:
    r.append(i)

for i in range(k):
    max_value = max(r)
    max_index = r.index(max_value)
    cut[max_index] += 1
    r[max_index] = a[max_index] / cut[max_index]

print(math.ceil(max(r)))

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal

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

for i in range(n):
  a[i] = [(-1) * a[i], Decimal(str((-1) * a[i])), (-1) * a[i], Decimal(str((-1) * a[i])), 1]

import heapq
heapq.heapify(a)

for _ in range(k):
  i = heapq.heappop(a)
  i[4] += 1
  i[0] = i[2] // i[4]
  i[1] = i[3] / i[4]
  heapq.heappush(a, i)

print((-1) * heapq.heappop(a)[0])

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
l = len(A)
B = [[a, 1] for a in A]
for i in range(K):
  B[0][1] += 1
  B[0][0] = A[0] / B[0][1]
  f = 0
  for j in range(1, l):
    if (B[j][0] == B[0][0] and B[j][1] < B[0][1]) or (B[j][0] < B[0][0]):
      B.insert(j, [B[0][0], B[0][1]])
      A.insert(j, A[0])
      f = 1
      break
  if f == 0:
    B.insert(l, [B[0][0], B[0][1]])
    A.insert(l, A[0])
  del B[0]
  del A[0]
print(int(math.ceil(B[0][0])))

Submission status: Time Limit Exceeded

Solution code:
import math

N,K = map(int, input().split())
A = list(map(int, input().split()))
epsilon = 10**(-9)
#A = [a-epsilon for a in A]

_min = 0
_max = max(A)

while _max - _min > epsilon:
  new = (_min+_max)/2
  if _min < int(new):
    new = int(new)
  times = sum([math.ceil(a/new)-1 for a in A])
  #print(_min, new, _max, times, [math.ceil(a/new)-1 for a in A])
  
  if times <= K:
    _max = new
  else:
    _min = new
  #print(_min, _max)

if  sum([math.ceil(a/_max)-1 for a in A]) <= K:
  print(math.ceil(_max))
else:
  print(math.ceil(_min))

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal

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

for i in range(n):
  a[i] = [(-1) * a[i], Decimal(str((-1) * a[i])), (-1) * a[i], Decimal(str((-1) * a[i])), 1]

import heapq
heapq.heapify(a)

for _ in range(k):
  i = heapq.heappop(a)
  i[4] += 1
  i[0] = i[2] // i[4]
  i[1] = i[3] / i[4]
  heapq.heappush(a, i)

print((-1) * heapq.heappop(a)[0])

Submission status: Time Limit Exceeded

Solution code:
#! coding: utf-8

import math

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

tmpA = [[x, 1, x] for x in A]
for _ in range(K):
    mval = max(tmpA)
    mind = tmpA.index(mval)
    tmpA[mind] = [float(mval[2]) / float(mval[1] + 1), mval[1]+1, mval[2]]
    
print(math.ceil(max(tmpA)[0]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[16]:


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


# In[41]:


cnt = 0
low = 0
high = max(A)
ans = max(A)
old = int(high)
mycount = 0
while low < high:
    mid = (high+low)/2
    cnt = sum([(x-0.001)//mid for x in A])
    if cnt <= K:
        high = mid
        ans = min(ans, int(-(-mid//1)))
    else:
        low = mid
    if int(mid) == old:
        mycount += 1
    if mycount == 100:
        break
    old = int(mid)
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

n, k = [int(_) for _ in input().split()]

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

a.sort()


l, r = 0, 10**9

while r-l > 1:

    m = (l+r)//2
    c = 0
    for i in range(n):
        if a[i] < m:
            continue
        c += a[i]//m-(a[i] % m == 0)
    # print(c, l, r, m)
    if c > k:
        l = m
    else:
        r = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
import math
from bisect import bisect

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

A.sort(reverse = True)
S = sum(A)

Bli = [1]*N
Ali2 = [[] for _ in range(N)]
remk = K

for i in range(N):
  w = A[i]*K//S
  Bli[i] += w
  remk -= w

for i in range(N):
  Ali2[i] = [A[i]/Bli[i],Bli[i]]
  
Ali2.sort()
for i in range(remk):
  aa = Ali2.pop()
  bb = aa[0]*aa[1]/(aa[1]+1)
  Ali2.append([bb,aa[1]+1])
  Ali2.sort()
  
print(math.ceil(Ali2[-1][0]))

Submission status: Time Limit Exceeded

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

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(mid, A):
  count = 0
  for i in range(N):
    if A[i] > mid:
      xx = A[i] / mid
      if xx % 1 != 0:
        xx += 1
      count += int(xx - 1)
      
  #print("c", count)
  if count > K:
    return False
  else:
    return True
  
#にぶたん
#A : 配列
def binary_search(A):
  N = 10 ** 9
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    if mid == 0:
      mid = 1
    #print(ng, ok, mid)
    if isOK(mid, A):
      ok = mid
    else:
      ng = mid
  return ok
  
#a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910]

print(binary_search(A))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

def main():
    N, K = map(int, input().split())
    h = []
    A = list(map(int, input().split()))

    for a in A:
        heapq.heappush(h, ((-1)*a, 1))

    for i in range(K):
        tup_h = heapq.heappop(h)
        n = tup_h[1]
        a = (-1)*tup_h[0]*n
        new_tup = ((-1)*(a/(n+1)), n+1)
        heapq.heappush(h, new_tup)

    res_tup = heapq.heappop(h)
    res = int(math.ceil((-1)*res_tup[0]))
    print(res)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import Fraction
import math
input = sys.stdin.readline

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

s = sum(a)

w = [(k * a[i]) // s for i in range(n)]
b = [Fraction(a[i] / (w[i] + 1)) for i in range(n)]

r = k - sum(w)

for i in range(r):
    b.sort()
    b[-1] = Fraction(b[-1].numerator, b[-1].denominator + 1)

b.sort()

print(math.ceil(b[-1]))