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:
def examA():
    X = I()
    if X<30:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)
    return

def examB():
    N, D = LI()
    cnt = 0
    for _ in range(N):
        x, y = LI()
        if x**2+y**2<=D**2:
            cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    N = 10**7
    K = I()
    cur = 0
    now = 1
    ans = -1
    for i in range(N):
        cur += 7 * now
        cur %= K
        if cur==0:
            ans = i+1
            break
        now *= 10
        now %= K
    print(ans)
    return

def examD():
    N = I()
    C = SI()
    cnt = 0
    l = 0; r = N-1
    while(l<r):
        while(l<N):
            if C[l]=="W":
                break
            l += 1
        while(0<=r):
            if C[r]=="R":
                break
            r -= 1
        if l<r:
            cnt += 1
            l += 1
            r -= 1
    ans = cnt
    print(ans)
    return

def examE():
    N, K = LI()
    A = LI()
    if K==0:
        print(max(A))
        return
    l = 0; r = inf
    for _ in range(80):
        now = dec((l+r)/2)
        cnt = 0
        for a in A:
            cur = a//now
            cnt += cur
        if K<cnt:
            l = now
        else:
            r = now
        #print(now,cnt)
        #input()
    ans = l
    if ans - ans//1>0:
        ans += 1
    ans //=1
    #print(now)
    print(ans)
    return

def examF():
    N, Q = LI()
    C = LI()
    for q in range(Q):
        l, r = LI()


    ans = [0]*Q
    for v in ans:
        print(v)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = dec("20000000000")
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 12

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Time Limit Exceeded

Solution code:
import heapq
from heapq import heapify
import math

n, k = map(int, input().split())
aa = list(map(lambda x: (-int(x), int(x), 1), input().split()))
heapq.heapify(aa)

for i in range(k):
    a = aa[0]
    d = a[2] + 1
    heapq.heapreplace(aa, (-a[1] / d, a[1], d))
print(math.ceil(-aa[0][0]))

Submission status: Time Limit Exceeded

Solution code:
def examA():
    X = I()
    if X<30:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)
    return

def examB():
    N, D = LI()
    cnt = 0
    for _ in range(N):
        x, y = LI()
        if x**2+y**2<=D**2:
            cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    N = 10**7
    K = I()
    cur = 0
    now = 1
    ans = -1
    for i in range(N):
        cur += 7 * now
        cur %= K
        if cur==0:
            ans = i+1
            break
        now *= 10
        now %= K
    print(ans)
    return

def examD():
    N = I()
    C = SI()
    cnt = 0
    l = 0; r = N-1
    while(l<r):
        while(l<N):
            if C[l]=="W":
                break
            l += 1
        while(0<=r):
            if C[r]=="R":
                break
            r -= 1
        if l<r:
            cnt += 1
            l += 1
            r -= 1
    ans = cnt
    print(ans)
    return

def examE():
    N, K = LI()
    A = LI()
    if K==0:
        print(max(A))
        return
    l = 0; r = inf
    for _ in range(100):
        now = dec((l+r)/2)
        cnt = 0
        for a in A:
            cur = a//now
            cnt += cur
        if K<cnt:
            l = now
        else:
            r = now
        #print(now,cnt)
        #input()
    ans = l
    if ans - ans//1>0:
        ans += 1
    ans //=1
    #print(now)
    print(ans)
    return

def examF():
    N, Q = LI()
    C = LI()
    for q in range(Q):
        l, r = LI()


    ans = [0]*Q
    for v in ans:
        print(v)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = dec("1000000000000")
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 16

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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)
a = [(-aa, 1) for aa in a]
heapq.heapify(a)

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
import math

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    q = []
    for i in range(N):
        heappush(q,(-A[i],0))

    for i in range(K):
        l, c = heappop(q)
        heappush(q,(l*(c+1)/(c+2),c+1))
    
    ans = 0
    while q:
        l,c = heappop(q)
        ans = max(ans,-l)
    print(math.ceil(ans))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

M=L
m=0
while M-m>=0.0001:
    x=(M+m)/2
    c=0
    for p in a:
        c+=ceil(p/x)-1
        if c>k:
            break
    if c<=k:
        M=x
    else:
        m=x
    x=(M+m)/2
print(ceil((M+m)/2))

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

ll=0
rr=10**9+1
for _ in range(10**3):
  #最も長い丸太がこれになる
  ans=(ll+rr)/2.0
  cnt=0
  for item in a:
    if item>ans:
	    cnt+=((-1*item)//ans)*(-1)-1
  if cnt<=k:
    rr=ans
  else:
    ll=ans
print(int((-1*ans//1)*(-1)))

Submission status: Time Limit Exceeded

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

ll=0
rr=10**9+1
for _ in range(10**5):
  #最も長い丸太がこれになる
  ans=(ll+rr)/2.0
  cnt=0
  for item in a:
    if item>ans:
	    cnt+=((-1*item)//ans)*(-1)-1
  if cnt<=k:
    rr=ans
  else:
    ll=ans
print(int((-1*ans//1)*(-1)))

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

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

queue = [(-a, 1) for a in A]
heapq.heapify(queue)

for _ in range(K):
    x, k = heapq.heappop(queue)
    t = x*k
    heapq.heappush(queue, (t/(k+1), k+1))

x, _ = heapq.heappop(queue)
x *= -1
print(math.ceil(x))

Submission status: Time Limit Exceeded

Solution code:
import heapq
from heapq import heapify
import math

n, k = map(int, input().split())
aa = list(map(lambda x: (-int(x), int(x), 1), input().split()))
heapq.heapify(aa)

for i in range(k):
    a = heapq.heappop(aa)
    d = a[2] + 1
    heapq.heappush(aa, (-a[1] / d, a[1], d))
print(math.ceil(-aa[0][0]))

Submission status: Time Limit Exceeded

Solution code:
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    aveA=sum(A)/N
    K_i=[int(A[i]/aveA*K/N) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    for i in range(res):
        maxi=dA.index(max(dA))
        K_i[maxi]+=1
        dA[maxi]=A[maxi]/(K_i[maxi]+1)
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import os
import heapq as h
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]


def main():
    n,k=map(int,input().split())
    ar=inpt()
    hp=[]
    h.heapify(hp)
    for i in ar:
        h.heappush(hp,(-i,-i,1))

    while(k):
        l,lg,ct=h.heappop(hp)
        v=abs(lg)/(ct+1)
        h.heappush(hp,(-v,lg,ct+1))
        k-=1
    ob=h.heappop(hp)
    ans=math.ceil(-1*ob[0])
    print(ans)

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

C = np.ones(N)


for i in range(K):
    L = A/C
    C[np.argmax(L)] += 1

print(int(max(np.ceil(A/C))))

Submission status: Time Limit Exceeded

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

LI = lambda: list(map(int, input().split()))

N, K = LI()
A = LI()


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


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()))
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)
  length.sort(key = lambda x: x[0], reverse=True)

print(math.ceil(length[0][0]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
As = list(map(int, input().split()))

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int(np.ceil(a/x))-1
        if cnt > k:
            return False
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-2
r = 10**9
while r-l > 10**-1:
    m = (l*r)**0.5
    if f(m):
        r = m
    else:
        l = m
print(int(np.ceil(l)))

Submission status: Time Limit Exceeded

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

for i in range(k):
  M=max(b)
  s=b.index(M)
  b[s]=b[s]*a[s]/(a[s]+1)
  a[s]=a[s]+1
  
print(math.ceil(max(b)))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
  chk=0
  for ai in a:
    # 長さx以下に分割するなら最小でtmp本にわかれる
    tmp=math.ceil(ai/x)
    chk+=tmp
  return chk<=n+k
l,r=0,max(a)
for _ in range(100):
  x=(l+r)/2
  if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
    l,r=l,x
  else:
    l,r=x,r
x=(l+r)/2
print(math.ceil(x))
#print(l,r,x)

Submission status: Time Limit Exceeded

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

hq = [(-a,-1,-a) for a in aa]
heapq.heapify(hq)

for _ in range(k):
    v,cnt,orig = heapq.heappop(hq)
    cnt *= -1
    cnt += 1
    v = orig / cnt
    cnt *= -1
    heapq.heappush(hq, (v,cnt,orig))

print(max([ceil(-a) for a,b,c in hq]))

Submission status: Time Limit Exceeded

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

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

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

def check(x):
    res = 0
    for i in a:
        res += i // x
    return res

l = 0
r = 10 ** 9 + 1
while not math.ceil(l) == math.ceil(r):
    x = (l + r) / 2
    if check(x) > k:
        l = x
    else:
        r = x
print(math.ceil(l))

Submission status: Time Limit Exceeded

Solution code:
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


n,k=mdata()
a=mdata()
q=[(-a[i],1) for i in range(n)]
heapify(q)
for i in range(k):
    a,b=heappop(q)
    a=-a
    a=(a*b)/(b+1)
    b+=1
    heappush(q,(-a,b))
a,b=heappop(q)
out(math.ceil(-a))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math

N,K = map(int,sys.stdin.readline().split())
a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
heapq.heapify(a)# a == [1,2,3]

for _ in range(K):
    _,ori,di = heapq.heappop(a)
    heapq.heappush(a, [-(ori)/(di+1),ori,di+1])

#print(a[0][0])
print(math.ceil(-a[0][0]))
# e = heapq.heappop(a) # e == 1
# heapq.heappush(a, 1) # a == [1,3,2]
# e = heqpq.heappushpop(a,4) # e == 1,a==[2,3,4]

Submission status: Time Limit Exceeded

Solution code:
import copy
n, k = [int(i) for i in input().split()]
logs = [int(i) for i in input().split()]
values = copy.copy(logs)
ans = [1 for i in range(len(logs))]
for i in range(k):
  index = values.index(max(values))
  ans[index] += 1
  values[index] = logs[index]/ans[index]
a = max(values)
if type(a) is int:
  print(a)
else:
  print(int(a)+1)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import math

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

H = []

for i in range(n):
    heapq.heappush(H, (-A[i], 1))

for i in range(k):
    long, num = heapq.heappop(H)
    heapq.heappush(H, (long*num/(num+1), num+1) )

print(math.ceil(-H[0][0]))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import heapq
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    q = []
    for index, i in enumerate(a):
        heapq.heappush(q, (-i, index, 1))
    for _ in range(k):
        length, index, count = heapq.heappop(q)
        heapq.heappush(q, (-a[index]/(count + 1), index, count + 1))
    length, index, count = heapq.heappop(q)
    print((a[index] + count - 1) // count)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
As = list(map(int, input().split()))

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int(np.ceil(a/x))-1
        if cnt > k:
            return False
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-6
r = 10**9
while r-l > 10**-1:
    # print(l,r)
    m = (l+r)/2
    if f(m):
        r = m
    else:
        l = m
print(int(np.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()))
num = [0]*N
hq = []
heapify(hq)
for i in range(N):
    a = A[i]
    heappush(hq,[-a,i])
for i in range(K):
    li = heappop(hq)
    num[li[1]] += 1
    a = A[li[1]]/(num[li[1]]+1)
    heappush(hq,[-a,li[1]])
ans = 0
for i in range(N):
    p = A[i]/(num[i]+1)
    ans = max(ans,p)
print(math.ceil(ans))

Submission status: Time Limit Exceeded

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

def check(k):
    cnt = 0
    for a in A:
        cnt += math.ceil(a/k) - 1
    return cnt <= K

l, r = 0, 10**30
while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

print(r)

Submission status: Time Limit Exceeded

Solution code:
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lo = 1
hi = 10**18
ans = max(arr)
while lo<=hi:
    t = 0
    m = (hi+lo)//2
    for i in range(n):
        if arr[i]>m:
            req = arr[i]//m
        else:
            req=  0
        t+=req
    if t<=k:
        ans = m
        hi = m-1
    else:
        lo = m+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify, heappop, heappush
from math import ceil
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
H = [ (-a, 1, a) for a in A]
heapify(H)
for k in range(K):
    _, n, L = heappop(H)
    heappush(H, (-L/(n+1), n+1, L))
ans = int(ceil(-H[0][0]))
print(ans)

Submission status: Time Limit Exceeded

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

x=0
y=max(A)

def f(l):
  nums=0
  for a in A:
    t=1
    while a/t>l:
      t+=1
    nums+=t-1
  if nums>K:
    return False
  else:
    return True

while y-x>1:
  tmp=(x+y)//2
  if f(tmp)==True:
    y=tmp
  else:
    x=tmp
    
print(y)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
As = list(map(int, input().split()))

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int(np.ceil(a/x))-1
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-6
r = 10**9
while r-l > 10**-1:
    # print(l,r)
    m = (l+r)/2
    if f(m):
        r = m
    else:
        l = m
print(int(np.ceil(l)))

Submission status: Time Limit Exceeded

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

import math
import heapq

q = []
for i, Ai in enumerate(A):
    heapq.heappush(q, (-Ai, 1, Ai))

for _ in range(K):
    penalty, cnt, base = heapq.heappop(q)
    heapq.heappush(q, (-base/(cnt + 1), cnt + 1, base))

penalty, cnt, base = heapq.heappop(q)
ans = int(math.ceil(-penalty))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
As = list(map(int, input().split()))

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int(np.ceil(a/x))-1
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-6
r = 10**9
while r-l > 10**-5:
    # print(l,r)
    m = (l+r)/2
    if f(m):
        r = m
    else:
        l = m
print(int(np.ceil(l)))

Submission status: Time Limit Exceeded

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

import heapq

Q=[]
for i in range(N):
    Q.append((-L[i],L[i],1))
heapq.heapify(Q)

for i in range(K):
    l,B,cnt=heapq.heappop(Q)
    heapq.heappush(Q,(-B/(cnt+1),B,cnt+1))
#print(Q)
#print(Q[0][0])

import math
ans=-Q[0][0]
print(math.ceil(ans))

Submission status: Time Limit Exceeded

Solution code:
import math

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

def solve(x):    #Trueで切り切れる
    cnt = 0
    for a in A:
        cnt += math.ceil(a / x) - 1
    return cnt <= K

left = 0
right = 10 ** 9 + 1

for _ in range(100):
    mid = (left + right) / 2
    if solve(mid):
        right = mid
    else:
        left = mid

print(math.ceil(right))

Submission status: Time Limit Exceeded

Solution code:
def main():
    from math import ceil

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

    def binary_search(*, ok, ng, func):
        for _ in range(80):
            mid = (ok + ng) / 2
            if func(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def is_ok(mid):
        cnt = 0
        for x in A:
            cnt += x // mid
            if x % mid == 0:
                cnt -= 1
        return cnt <= K

    ma = max(A)
    res = binary_search(ok=ma, ng=0, func=is_ok)

    print(ceil(res))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, D = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype = 'float')
B = [1]*N
C = np.copy(A)
for i in range(D):
  tmp = np.argmax(C)
  B[tmp] += 1
  C[tmp] = (A[tmp]) / (B[tmp])

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

Submission status: Time Limit Exceeded

Solution code:
import math
import heapq  # heapqライブラリのimport
from collections import deque
a = []
heapq.heapify(a)
N,K=map(int,input().split())
L=list(map(int,input().split()))
for i in range(N):
    heapq.heappush(a,(-L[i],1))  # 要素の挿入
for i in range(K):
    b,count=heapq.heappop(a)
    b=b*count/(count+1)
    heapq.heappush(a,(b,count+1))
b,count=heapq.heappop(a)
print(math.ceil(-b))

Submission status: Time Limit Exceeded

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

hq = [(-a,-1,-a) for a in aa]
heapq.heapify(hq)

for _ in range(k):
    v,cnt,orig = heapq.heappop(hq)
    cnt *= -1
    cnt += 1
    v = orig / cnt
    cnt *= -1
    heapq.heappush(hq, (v,cnt,orig))

print(max([ceil(-a) for a,b,c in hq]))

Submission status: Time Limit Exceeded

Solution code:
def examA():
    X = I()
    if X<30:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)
    return

def examB():
    N, D = LI()
    cnt = 0
    for _ in range(N):
        x, y = LI()
        if x**2+y**2<=D**2:
            cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    N = 10**7
    K = I()
    cur = 0
    now = 1
    ans = -1
    for i in range(N):
        cur += 7 * now
        cur %= K
        if cur==0:
            ans = i+1
            break
        now *= 10
        now %= K
    print(ans)
    return

def examD():
    N = I()
    C = SI()
    cnt = 0
    l = 0; r = N-1
    while(l<r):
        while(l<N):
            if C[l]=="W":
                break
            l += 1
        while(0<=r):
            if C[r]=="R":
                break
            r -= 1
        if l<r:
            cnt += 1
            l += 1
            r -= 1
    ans = cnt
    print(ans)
    return

def examE():
    N, K = LI()
    A = LI()
    l = 0; r = inf
    for _ in range(150):
        now = dec((l+r)/2)
        cnt = 0
        for a in A:
            cur = a//now
            cnt += cur
        if K<cnt:
            l = now
        else:
            r = now
        #print(now,cnt)
        #input()
    ans = now
    #print(now)
    if now%1>0:
        ans = (ans+1)//1
    else:
        ans = ans//1
    print(ans)
    return

def examF():
    N, Q = LI()
    C = LI()
    for q in range(Q):
        l, r = LI()


    ans = [0]*Q
    for v in ans:
        print(v)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Time Limit Exceeded

Solution code:
import heapq

ceil = lambda a, b: (a + b - 1) // b

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

h = [(-a, a, 1) for a in A]
heapq.heapify(h)
for _ in range(K):
    l, a, ct = heapq.heappop(h)
    ct += 1
    heapq.heappush(h, (-a / ct, a, ct))
_, a, ct = heapq.heappop(h)
print(ceil(a, ct))