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 numpy
import copy
import math
N,K = list(map(int,input().split()))

A = list(map(int,input().split()))
A2 = A.copy()
A3 = [1]*N
for i in range(K):
    index = numpy.argmax(A2)
    A2[index] = A[index]/(A3[index]+1)
    A3[index] += 1

print(math.ceil(max(A2)))

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#import collections
#import math

#f = open('./input_E.txt')
#
#N,K = map(int, f.readline().split())
#A = list(map(int, f.readline().split()))

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

if K == 0:
    ans = max(A)
else:
    A.sort(reverse=True)
    
    All_length = sum(A)
    KK = K+N-1
    lm = All_length/(KK+1)
    
    k_list = [int(Ai//lm) for Ai in A]
    X_list = [Ai%lm for Ai in A]
    
    sum_k = sum(k_list)
    res_cut = KK-sum_k
    
    zero_k = 0
    for i in range(1,N+1):
        if k_list[-i] == 0:
            zero_k +=1
        else:
            break
    
    if res_cut > 0:
        ans_kouho = []
        for i in range(-zero_k,0):
            ans_kouho.append(X_list[i])
        for i in range(res_cut):
            for j in range(N-zero_k):
                ans_kouho.append((X_list[j]-i*lm)/k_list[j])
        
        ans_kouho.sort(reverse=True)
        ans = ans_kouho[res_cut] + lm
        ans = int(ans)+1
    else:
        ans = int(lm)+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

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)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

asum = sum(Alist)
cut = []
length = []
for n in range(N):
    tmp = K * Alist[n] / asum
    cut.append(int(tmp) + 1)
    length.append(Alist[n] / (int(tmp)+1))

amari = K - sum(cut) + N
length = np.array(length)

for _ in range(amari):
    max_idx = np.argmax(length)
    cut[max_idx] += 1
    length[max_idx] = Alist[max_idx] / cut[max_idx]

ans = max(length)

if ans%1>0:
    print(int(ans)+1)
else:
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n, k = inpl()
A = inpl()
# if n == 1:
#     print(math.ceil(k))
A.sort()
A.reverse()
hq = []
for i in A:
    heappush(hq, (-1 * i, i, 1))
for i in range(k):
    t = heappop(hq)
    # t1 = heappop(hq)
    # t2 = heappop(hq)
    if t[1] % ((t[2]+1)) == 0:
        ad = 0
    else:
        ad = 1
    val = t[1] // (t[2]+1) + ad
    heappush(hq, (-1*val, t[1], t[2]+1))
ans = heappop(hq)
print(-1 * ans[0])


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math


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

    def value(self):
        return self.valuee

    def ups(self):
        self.s += 1
        self.valuee = self.v / self.s

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


def _run(N, K, As):
    a = []
    for v in As:
        heapq.heappush(a, Value(v))

    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 heapq
import math

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

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

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

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

max_length, _, _ = heapq.heappop(hq)
print(math.ceil(-max_length))

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 int(_min)<int(_max):
  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)

print(math.ceil(_max))

Submission status: Time Limit Exceeded

Solution code:
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 10 ** 16
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = map(int, open(0).read().split())
print(binary_search(K))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
alist=list(map(int,input().split()))
#print(alist)

def num_cut(x):
  if x==0:
    return False
  
  ret=0
  for a in alist:
    ret+=-(-(a-x)//x)
  return ret

#for i in range(1,max(alist)):
#  print(i,num_cut(i))

l=1
r=max(alist)+1
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  
  if num_cut(mid-1)>K and num_cut(mid)<=K:
    print(mid)
    break
  elif num_cut(mid)<=K:
    r=mid
  else:
    l=mid

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

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

    def value(self):
        return self.v / self.s

    def ups(self):
        self.s += 1

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


def _run(N, K, As):
    a = []
    for v in As:
        heapq.heappush(a, Value(v))

    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:
n,k=map(int,input().split())
a=list(map(int,input().split()))



sho=1
dai=max(a)
for jfdlas in range(100):
    now=(sho+dai)//2
    gokei=0
    for i in range(n):
        gokei+=(a[i]-1)//now
        #print(gokei)
    if(gokei<=k):
        dai=now
    else:
        sho=now
    #print(now,gokei,sho,dai)


print(dai)
#gokei=0
#for i in range(n):
#    gokei+=(a[i]-1)//
#if(gokei>k):
#    print(sho)
#else:
#    print(dai)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
logs = []
heapq.heapify(logs)
for a in A:
    heapq.heappush(logs, [-a, -a, 1])


for _ in range(K):
    log = heapq.heappop(logs)
    dividing_equal = log[2] + 1
    cut_log = log[1] / dividing_equal
    origin_log = log[1]

    heapq.heappush(logs, [cut_log, origin_log, dividing_equal])
print(math.ceil(-logs[0][0]))

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)
for _ 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 sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = 0
for i in range(N):
    S += A[i]
vmin = 0
for i in range(N):
    a = A[i]
    kk = a/math.ceil(1+a*K/S)
    vmin = max(vmin,kk)
v = math.floor(vmin)
p = max(1,v-2)
for i in range(p,p+10**6):
    c = 0
    if i == 1:
        for j in range(N):
            a = A[j]
            c += a-1
    else:           
        for jj in range(N):
            a = A[jj]
            c += (a-1) // i 
    if c <= K:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()

    hq = [(-i, i, 1) for i in A]
    heapq.heapify(hq)
    
    for _ in range(K):
        _, a, d = heapq.heappop(hq)
        heapq.heappush(hq, (-a / (d + 1), a, d + 1))

    # print(hq)
    ans_t = heapq.heappop(hq)
    print(math.ceil(-ans_t[0]))

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 10 ** 18
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = map(int, open(0).read().split())
print(binary_search(K))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import heapq

N, K = map(int, input().split())
A_list = list(map(int, input().split()))
heap_list = []

for i in range(N):
    heapq.heappush(heap_list, (-1 * A_list[i], 1))

for i in range(K):
    min_tuple = heapq.heappop(heap_list)
    min_num = min_tuple[0] * min_tuple[1] / (min_tuple[1] + 1)
    min_div_num = min_tuple[1] + 1
    heapq.heappush(heap_list, (min_num, min_div_num))

ans = heapq.heappop(heap_list)[0] * -1
ans = int(ans) + (0 if ans % 1 == 0 else 1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N,K = [int(i) for i in input().split()]
A = [[-int(i),int(i),0] for i in input().split()]
heapq.heapify(A)
for _ in range(K):
    a = heapq.heappop(A)
    a[2] += 1
    a[0] = -(a[1]//(a[2]+1))-1
    heapq.heappush(A, a)
print(-A[0][0])

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from fractions import Fraction
n,k, *aa = map(Fraction, open(0).read().split())

left = max(1,k/2)
right = left * 4
mid = (left + right)/2
summ = sum(aa)

while 1:
    x = [(ceil((mid)*a/summ), a) for a in aa]
    score = sum(a[0]-1 for a in x)
    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))
        break

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

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

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

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

for _ in range(K):
    _, c, l = heapq.heappop(hq)
    heapq.heappush(hq, (-l/(c+1), c+1, l))

max_length, _, _ = heapq.heappop(hq)
print(math.ceil(-max_length))

Submission status: Time Limit Exceeded

Solution code:
import math
import bisect

N, K = map(int, input().split())
leng = list(map(int, input().split()))
leng.sort()
cut = [0] * N
# A = [maruta(a, 0) for a in A_tmp]
for a in range(K):
    new_cut = cut.pop() + 1
    new_leng = leng.pop() * (new_cut / (new_cut + 1))
    idx = bisect.bisect_left(leng, new_leng)
    leng.insert(idx, new_leng)
    cut.insert(idx, new_cut)
    # print(new_leng, new_cut)
print(math.ceil(leng[-1]))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np
import math

setrecursionlimit(10 ** 7)

n,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))

a.sort()
a = np.array(a,dtype=np.int64)

low = 0
hi = 10**9
point = 0

while hi-low > 0.000000001:
    ave = (hi+low)/2
    if np.ceil(a//ave).sum() <= k:
        hi = ave
    else:
        low = ave

print(math.ceil(ave))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n, k = inpl()
A = inpl()

hq = []
for i in A:
    heappush(hq, (-1 * i, i, 1))
for i in range(k):
    t = heappop(hq)
    val = math.ceil(t[1] / (t[2]+1))
    heappush(hq, (-1*val, t[1], t[2]+1))
ans = heappop(hq)
print(-1 * ans[0])


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Time Limit Exceeded

Solution code:
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
mc = [0] * len(a)
import copy
v = copy.deepcopy(a)

while True:
	if k == 0:
		break
	mi = v.index(max(v))
	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:
from math import ceil
from fractions import Fraction
n,k, *aa = map(Fraction, open(0).read().split())

left = k/2
right = 2*k
mid = (left + right)/2
summ = sum(aa)

while 1:
    x = [(ceil((mid)*a/summ), a) for a in aa]
    score = sum(a[0]-1 for a in x)
    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))
        break

Submission status: Time Limit Exceeded

Solution code:
import math


def f(A, m, K):
    p = sum([a // m for a in A])
    if p > K:
        return False
    else:
        return True


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


left = 1
right = 10 ** 9 + 1

while math.ceil(left) != math.ceil(right):
    m = (left + right) / 2

    if f(A, m, K):
        right = m
    else:
        left = m


print(math.ceil(m))

Submission status: Time Limit Exceeded

Solution code:
import math

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

t = [0]*n

for i in range(n):
    t[i] = round(k * a[i] / sum(a))
    a[i] = math.ceil(a[i] / (t[i] + 1))

print(max(a))

Submission status: Time Limit Exceeded

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

h=[(-A[i],1) for i in range(len(A))]
heapq.heapify(h)
for i in range(K):
  a=heapq.heappop(h)
  b=a[0]
  c=a[1]
  heapq.heappush(h,(c*b/(c+1),c+1))


ans=heapq.heappop(h)
print(math.ceil(-ans[0]))

Submission status: Time Limit Exceeded

Solution code:
import math

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

A.sort()

R = A[N-1]
L = 1

if K == 0:
    print(R)
else:
    while math.ceil(L) < math.ceil(R):
        m = (L+R)/2
        cnt = 0
        for i in range(N):
            if A[N-1-i] > m:
                cnt += math.ceil(A[N-1-i]/m) -1
            else:
                break

        if cnt <= K:
            R = m
        else:
            L = m
    print(math.ceil(R))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
# from decimal import Decimal

N, K = map(int, input().split())
A = list(map(int, input().split()))
# N, K = 2*10**5, 1
# A = [10**9]*N

def solve(x):
    m = 0
    for a in A:
        m += a//x - (a%x == 0)
    # print(x, m)
    return m <= K

A = [a*10**10 for a in A]

ok, ng = max(A), 0
while abs(ok-ng > 1):
    mid = (ok+ng)//2
    # print(mid)
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(-(-mid//10**10))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
    print(a[0])
    exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
    d = max(math.floor(aa / mean_a)-1, 1)
    q.append((-aa/d, d))
    k -= (d-1)
heapq.heapify(q)

for _ in range(k):
    aa, n = heapq.heappop(q)
    heapq.heappush(q, (aa*n/(n+1), n+1))

ans, _ = heapq.heappop(q)
print(math.ceil(-ans))

Submission status: Time Limit Exceeded

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

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

b = []
for v in a:
    b.append([-v, -v, 1])

heapify(b)
for _ in range(k):
    x, y, z = heappop(b)
    heappush(b, [y/(z+1), y, z+1])

res = heappop(b)
print(ceil(-res[0]))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
    print(a[0])
    exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
    d = max(math.floor(aa / mean_a)-2, 1)
    q.append((-aa/d, d))
    k -= (d-1)
heapq.heapify(q)

for _ in range(k):
    aa, n = heapq.heappop(q)
    heapq.heappush(q, (aa*n/(n+1), n+1))

ans, _ = heapq.heappop(q)
print(math.ceil(-ans))

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, a, 1))

    for i in range(K):
        tup_h = heapq.heappop(h)
        a = tup_h[1]
        n = tup_h[2]
        new_tup = ((-1)*(a/(n+1)), a, 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:
from math import floor, ceil


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    lower = 1
    upper = a[-1]
    while upper - lower >= 0.25 or floor(upper) != floor(lower):
        target = (lower + upper) / 2
        now = 0
        for i in range(n):
            now += ceil(a[i] / target) - 1
        if now > k:
            lower = target
        else:
            upper = target
    print(ceil(lower) if k > 0 else a[-1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
# 初期配分
sum_of_As = sum(As)
A_cut = []
toK = 0
for a in As:
    n_c = K * a//sum_of_As
    A_cut.append([a/(n_c+1), n_c+1])
    toK += n_c
# print(A_cut)
# 調整
while toK < K:
    # print('more cut')
    A_cut = sorted(A_cut, key=lambda x: x[0])
    # print(A_cut)
    A_cut[-1] = [A_cut[-1][0]*A_cut[-1][1]/(A_cut[-1][1] + 1), A_cut[-1][1]+1]
    # print(A_cut[-1])
    toK += 1
A_re = [i for i, _ in A_cut]
print(math.ceil(max(A_re)))

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify,heappop,heappush
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(N):
  A[i] = [-A[i],A[i],0]
  
heapify(A)
for i in range(K):
  a = heappop(A)
  x = a[2] + 1
  a[2] = x
  a[0] = -(a[1] / (x + 1))
  heappush(A, a)
  
ans = -heappop(A)[0]
print(math.ceil(ans))

Submission status: Time Limit Exceeded

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
A = getList()
A = [-i for i in A]

# 単純に大きいのを1 / 2していては
# 3.5, 3.5, 4.5, 2.25, 2.25ができるのでダメ

def f(target):
    alta = copy.deepcopy(A)
    heapq.heapify(alta)
    for i in range(K):
        max_value = heapq.heappop(alta) * (-1)
        max_value_a = min(target, max_value)
        max_value_b = max_value - max_value_a
        heapq.heappush(alta, max_value_a * (-1))
        heapq.heappush(alta, max_value_b * (-1))

    u = heapq.heappop(alta) * (-1)
    if u <= target:
        return True
    else:
        return False

ng = 0
ok = 10 ** 12 + 1
for i in range(100):
    mid = (ng + ok) / 2
    # midがでかすぎるなら上限を下げる
    if f(mid):
        ok = mid
    # midが小さすぎるなら下限を上げる
    else:
        ng = mid

print(math.ceil(ng))

Submission status: Time Limit Exceeded

Solution code:
import math

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

A.sort()
A.reverse()

R = A[0]
L = 1

if K == 0:
    print(R)
else:
    while math.ceil(L) < math.ceil(R):
        m = (L+R)/2
        cnt = 0
        for i in range(N):
            if A[i] > m:
                cnt += math.ceil(A[i]/m) -1
            else:
                break

        if cnt <= K:
            R = m
        else:
            L = m
    print(math.ceil(R))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

N,K=input().split()
N,K=int(N),int(K)
_A=input().split()
A=[]

for a in _A:
    A.append(int(a))

t=[]
for idx,i in enumerate(A):
    t.append((-i,idx))
heapq.heapify(t)

toubun=[1]*N

for i in range(K):
    a=heapq.heappop(t)
    toubun[a[1]]+=1
    heapq.heappush(t,(-A[a[1]]/toubun[a[1]],a[1]))

print(math.ceil(-heapq.heappop(t)[0]))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import heapq
push = heapq.heappush
pop = heapq.heappop
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()))

hp = []
for i in lst1:
    push(hp,(-i,i,1))

for i in range(k):
    res = pop(hp)
    res2 = [0]*3
    res2[0] = -res[1]/(res[2]+1)
    res2[1] = res[1]
    res2[2] = res[2]+1
    push(hp,tuple(res2))

print(math.ceil(-pop(hp)[0]))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from decimal import Decimal

N, K = map(int, input().split())
A = list(map(int, input().split()))
# N, K = 2*10**5, 1
# A = [10**9]*N

def solve(x):
    m = 0
    for a in A:
        m += a//x - (a%x == 0)
    # print(x, m)
    return m <= K

ok, ng = Decimal(max(A)), Decimal(0)
while abs(ok-ng > Decimal(0.1**6)):
    mid = (ok+ng)/Decimal(2)
    # print(mid)
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ceil(mid))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import numpy as np
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A_num = np.array(A)
B = [1 for _ in range(N)]
for _ in range(K):
    index = np.argmax(A_num)
    B[index] += 1
    A_num[index] = (A[index]-1)//B[index] + 1
print(np.max(A_num))

Submission status: Time Limit Exceeded

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
A = getList()
A = [-i for i in A]

# 単純に大きいのを1 / 2していては
# 3.5, 3.5, 4.5, 2.25, 2.25ができるのでダメ

def f(target):
    alta = copy.deepcopy(A)
    heapq.heapify(alta)
    for i in range(K):
        max_value = heapq.heappop(alta) * (-1)
        max_value_a = min(target, max_value)
        max_value_b = max_value - max_value_a
        heapq.heappush(alta, max_value_a * (-1))
        heapq.heappush(alta, max_value_b * (-1))

    u = heapq.heappop(alta) * (-1)
    if u <= target:
        return True
    else:
        return False

ng = 0
ok = 10 ** 12 + 1
while ok - ng > 10 ** -5:
    mid = (ng + ok) / 2
    # midがでかすぎるなら上限を下げる
    if f(mid):
        ok = mid
    # midが小さすぎるなら下限を上げる
    else:
        ng = mid

print(math.ceil(ng))

Submission status: Time Limit Exceeded

Solution code:
import copy
import math

n,k = map(int,input().split())
a = list(map(int,input().split()))
a2 = copy.copy(a)
x = [0] * n
for i in range(k):
    tmax = max(a2)
    tindex = a2.index(tmax)
    x[tindex] += 1
    a2[tindex] = a[tindex]/(x[tindex]+1)
max0 = 0
for i in range(n):
    max0 = max(max0,math.ceil(a[i]/(x[i]+1)))
print(max0)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

def resolve():
    _,k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    heap = []
    for a in A:
        heapq.heappush(heap, (-a, -a, 1))
    
    while k > 0:
        a = heapq.heappop(heap)
        origin = a[1]
        denom = a[2]
        denom += 1
        new = (origin/denom, origin, denom)
        heapq.heappush(heap, new)
        k -= 1

    a = heapq.heappop(heap)
    ans = a[0]*-1
    print(math.ceil(ans))
    
resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D
from functools import reduce as R
import heapq as H

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

class Log(object):
    def __init__(self, id, val):
        self.id = id
        self.val = val
    def __repr__(self):
        return f'{self.val}@{self.id}'
    def __lt__(self, other):
        return self.val > other.val
      
n, k = I()
og_logs = Is()
logs = [Log(i, log) for i, log in enumerate(og_logs)]
cache = [1] * len(logs)
H.heapify(logs)

for _ in range(k):
  l = H.heappop(logs)
  cache[l.id] += 1
  H.heappush(logs, Log(l.id, og_logs[l.id] / cache[l.id]))

l = H.heappop(logs)
print(C(l.val))

Submission status: Time Limit Exceeded

Solution code:
from math import floor, ceil


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    lower = 1
    upper = a[-1]
    for _ in range(10000):
        target = (lower + upper) / 2
        now = 0
        for i in range(n):
            now += ceil(a[i] / target) - 1
        if now > k:
            lower = target
        else:
            upper = target
    print(ceil(lower) if k > 0 else a[-1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = len(A)
B = [[a, 1] for a in A]
for i in range(K):
  m = 0
  j = -1
  M = 0
  for k in range(l):
    if (B[k][0] > m) or (B[k][0] == m and B[k][1] > M):
      m = B[k][0]
      j = k
      M = B[k][1]
  B[j][1] += 1
  B[j][0] = A[j] / B[j][1]
print(int(math.ceil(max(B)[0])))