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: Wrong Answer

Solution code:
import sys

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

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

def rf(mm):
    if mm==0:
        return sum(a)
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    elif rf(m-1)==n+k:
        um=m-1
        m=(lm+m)//2
    else:
#        print(m)
        break

#for mi in range(m,0,-1):
#    if rf(mi)!=(n+k):
#        break
print(m)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
#AiをKi回切ると仮定した場合Ai/(Ki+1)
#Kiの総和はK
#つまりKiを動かしたときのmax_i Ai/(Ki+1)を最小化する
#2分探索！
#最小値をmidにするための回数はK回以内でOKか？
#計算量はNlog(maxA)なので通りそう
low=1
high=max(A)+1
#low できない
#high できる
while(high-low>1):
    mid=(high+low)//2
    #ceil(Ai/(Ki+1))=mid
    #ceil(x)-1<x<=ceil(x)
    #x<=ceil(x)<x+1
    #mid-1<Ai/(Ki+1)<=mid
    #Ai/(Ki+1)<=mid<Ai/(Ki+1)+1
    #Ai<=mid*(Ki+1)<Ai+Ki+1
    #Ai/mid<=Ki+1<Ai+Ki+1
    #floor(Ai/mid)<=Ai/mid<floor(Ai/mid)+1
    #Ai/midが整数ならKi=Ai/mid-1
    #Ai/midが整数でないならばKi=Ai/mid
    tmp=0
    for i in range(N):
        tmp+=A[i]//mid
        if A[i]%mid==0:
            tmp-=1
    if tmp<=K:
        high=mid
    else:
        low=mid
print(high)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while R-L >= 1:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
if int(R) - int(L) == 0:
    print(int(R)+1)
else:
    print(int(R))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while R-L > 1:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
print(int(R))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while R-L >= 1:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
print(int(R))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N, K = (int(n) for n in input().split())
A = [int(n) for n in input().split()]

def is_ok(X):
    ret = 0
    for log in A:
        ret += -(-log//X) - 1
    return ret <= K

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(1, 10**18))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N, K = (int(n) for n in input().split())
A = [int(n) for n in input().split()]

def is_ok(X):
    ret = 0
    for log in A:
        ret += -(-log//X) - 1
    return ret <= K

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(1, max(A)))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N, K = (int(n) for n in input().split())
A = [int(n) for n in input().split()]

def SplitTo(X):
    ret = 0
    for log in A:
        ret += -(-log//X) - 1
    return ret

l = 1 
r = max(A) 
mid = 0

while l <= r:
    mid = (l+r) // 2
    ret = SplitTo(mid)
    yes = ret <= K
    if yes:
        r = mid - 1
    else:
        l = mid + 1

print(mid)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
 
N, K = map(int, readline().split())
A = list(map(int, readline().split()))
 
l = 0
r = 10**10
 
def test(m):
  return sum((a + m - 1) // m for a in A) <= K

while l + 1 < r:
  m = (l + r) // 2
  if test(m):
  	r = m
  else:
    l = m
print(r)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while int(R)-int(L) > 1:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
if L == int(L):
    print(int(L))
else:
    print(int(L)+1)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while int(R)-int(L) > 1:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
print(int(R))

Submission status: Wrong Answer

Solution code:
import math

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

ceil = math.ceil

max_a = max(A)
target_length = max_a//2 + 1
min_a = 0




while True:
    cnt = 0
    for a in A:
        cut_num = (a + target_length - 1)//target_length
        cnt += cut_num
    if cnt > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Submission status: Wrong Answer

Solution code:
import math

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

ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

cnt = 0


while cnt < 30:
    cnt += 1
    target_a = [ceil(x/target_length)-1 for x in a]
    if sum(target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Submission status: Wrong Answer

Solution code:
import math

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

log2 = math.log2
ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

while True:
    target_a = [x/target_length for x in a]
    log2_target_a = [ceil(log2(x))-1 for x in target_a]
    if sum(log2_target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Submission status: Wrong Answer

Solution code:
import math

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

ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

cnt = 0

print(f'max:{max_a},target:{target_length}')

while cnt < 30:
    cnt += 1
    target_a = [ceil(x/target_length)-1 for x in a]
    if sum(target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
        print(f'False, target:{target_length}')
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2
        print(f'True, target:{target_length}')

Submission status: Wrong Answer

Solution code:
import math

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

log2 = math.log2
ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

while True:
    target_a = [x/target_length for x in a]
    log2_target_a = [ceil(log2(x))-1 for x in target_a]
    if sum(log2_target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(min_a)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Submission status: Wrong Answer

Solution code:
import math

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

log2 = math.log2
ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

while True:
    target_a = [x/target_length for x in a]
    log2_target_a = [ceil(log2(x)) for x in target_a]
    if sum(log2_target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(min_a)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    eps = 1e-8
    while int(l) != int(r):
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += (a-eps) // test
        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test
    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += (a - eps) // int(l)
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)





if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
log=list(map(int,input().split()))
a=1
b=max(log)
if b==1:
  print(1)
  exit()
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(log[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)

Submission status: Wrong Answer

Solution code:
import math
N,K=map(int,input().split())
a=list(map(float,input().split()))
lowest=0
highest=max(a)
antemp=0

while True:
    temp=(lowest+highest)/2
    for ans in a:
        antemp+=math.ceil(ans/temp)-1
    if antemp<K:
        highest=temp
    elif antemp>K:
        lowest=temp
    else:
        highest=temp
        if highest-lowest<0.1:
            print(math.ceil(temp))
            exit()
    antemp=0

Submission status: Wrong Answer

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def Ra():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################


def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    # calc
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+c[cur]
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d

class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo



show_flg=False
show_flg=True

ans=0


n,k,*a=map(int,open(0).read().split())

def check(m):
    t=0
    for i in a:
        t+=max(int(i/m+1)-1,0)
    return t>k
        
l,r=0,10**9+10
c=0
while c<100:
    c+=1
    m=(r+l)/2
    l,r,*_=[l,m,r][check(m)::]

print(int(l+1))

Submission status: Wrong Answer

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def Ra():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################


def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    # calc
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+c[cur]
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d

class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo



show_flg=False
show_flg=True

ans=0


n,k,*a=map(int,open(0).read().split())

def check(m):
    t=0
    for i in a:
        t+=max(int(i/m+1)-1,0)
    return t>k
        
l,r=0,10**9+10
c=0
while c<100:
    c+=1
    m=(r+l)/2
    l,r,*_=[l,m,r][check(m)::]

print(int(l+0.5))

Submission status: Wrong Answer

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def Ra():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################


def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    # calc
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+c[cur]
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d

class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo



show_flg=False
show_flg=True

ans=0


n,k,*a=map(int,open(0).read().split())

def check(m):
    t=0
    for i in a:
        t+=max((2*i+2*m)//(2*m-1)-1,0)
    return t>k
        
l,r=0,10**9+10
while r-l>1:
    m=(r+l)//2
    l,r,*_=[l,m,r][check(m)::]

print(l)