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

Solution (Python):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=10**9
while ok-ng >1:
  l = (ng+ok)//2
  kt=0
  for i in range(n):
    kt += a[i]//l - (0 if a[i]%l else 1)
  if kt <= k:
    ok = l
  else:
    ng = l
print(ok)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    def check(t):
        cnt = 0
        for ai in A:
            cnt += -(-ai // t) - 1
        return cnt <= K
    
    ok, ng = 10 ** 9, 0
    while 1 < ok - ng:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    solve()

Solution (Python):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=10**9
while ok-ng >1:
  l = (ng+ok)//2
  kt=0
  for i in range(n):
    kt += a[i]//l - (0 if a[i]%l else 1)
  if kt <= k:
    ok = l
  else:
    ng = l
print(ok)

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

left = 0
right = max(a)

while right - left > 1:
    mid = (right + left) // 2
    tmp = 0
    for i in a:
        tmp += (i - 1) // mid
    
    if tmp <= k:
        right = mid
    else:
        left = mid
        
print(right)

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

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

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

print(math.ceil(suki))

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
s = sum(a)
x = [0]*n
y = 0
r = 0
for i in range(n):
    y = int(a[i]/s*k)
    x[i] = [i, y, a[i]/(y+1), a[i]]
    r += y
x.sort(key= lambda val : val[2],reverse=True)
for i in range(k-r):
    x[i][1] += 1
ans = 0
for i in range(n):
    ans = max(ans, x[i][3]/(x[i][1]+1))
print(int(-(-ans//1)))

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

def f(x):
    return sum((a+x-1)//x - 1 for a in A)

l = 0
r = 10**9+1 
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) <= K:
        r = mid
    else:
        l = mid
print(r)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=10**9
while r>l+1:
    mid=(l+r)//2
    res=0
    for i in range(n):
        res+=(math.ceil(a[i]/mid)-1)
    if res<=k:
        r=mid
    else:
        l=mid
print(r)

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

l, r = sum(A)//(N+K), A[-1]
if l == 0: l = 1

if sum([(a-1)//l for a in A]) <= K:
    print(l)
    exit()

while l+1 < r:
    m = (l+r) // 2

    cuts = sum([(a-1)//m for a in A])

    if cuts <= K:
        r = m
    else:
        l = m

print(r)

Solution (Python):
n,k=map(int, input().split())
*a,=map(int, input().split())
mx=max(a)
mn=10**(-9)
from math import ceil
while mx-mn>10**(-5):
    md=(mx+mn)/2
    cnt=0
    for ai in a:
        cnt+=ceil(ai/md)-1
    if cnt<=k:
        mx=md
    else:
        mn=md
print(ceil(mn))

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

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

print(high)

Solution (Python):
n,k,*a=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
  m=l+r>>1
  if sum(0--i//m for i in a)>n+k: l=m
  else: r=m
print(r)

Solution (Python):
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
M = max(A)
l,r = 1,M
cnt = 0
while l<=r:
    cnt = 0
    mid = (l+r)//2
    for a in A:
        tmp= a//mid if a>mid else 0
        cnt += tmp
    if cnt <=k:
        r = mid-1
    else:
        l = mid+1
print(l)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    def check(x):
        cnt = 0
        for a in A:
            cnt += (a - 1) // x
        return cnt <= k

    l = 0
    r = 10 ** 10
    while r - l > 1:
        m = (l + r) // 2
        if check(m):
            r = m
        else:
            l = m
    print(r)
resolve()

Solution (Python):
n, k = map(int, input().split())
l = list(map(int, input().split()))
lo, hi = 1, 9999999999999999
while lo < hi:
    mid = (lo + hi) // 2
    cnt = 0
    for i in range(n):
        if l[i] % mid == 0: cnt += (l[i] // mid) - 1
        else: cnt += (l[i] // mid)
    if cnt <= k: hi = mid
    else: lo = mid + 1
print(lo)

Solution (Python):
n, k  = map(int, input().split())
a = list(map(int, input().split()))
def check(x):
    res = 0
    for i in range(n):
        res +=  (a[i]-1) // x
    if res <= k:
        return True
    else:
        return False
r = 1000000000
if check(1):
    print(1)
    exit()
else:
    l = 1
    while r > l+1:
        mid = (r+l)//2
        if check(mid):
            r = mid
        else:
            l = mid
    print(r)

Solution (Python):
n,k,*a=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
  m=l+r>>1
  if sum(0--i//m for i in a)<=n+k: r=m
  else: l=m
print(r)

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

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

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

print(math.ceil(suki))

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

while(right-left>=1):
    numofcut=0
    
    for i in range(N):
        numofcut+=math.ceil(A[i]/mid)-1
    
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    mid=max((left+right)//2,1)
    if mid==1:
        break
print(mid)

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

l = 0
r = 10**10

while r > l + 1:
    m = (r+l)//2
    count = 0
    for i in a:
        if i <= m:
            continue
        count += (i)//m
        
    if count > k:
        l = m
    else:
        r = m
    
print(r)

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


def is_ok(i):
    su = 0
    for a in A:
        su += math.ceil(a / i) - 1
    if su <= K:
        return True
    else:
        return False

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

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

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

while(right-left>=1):
    numofcut=0
    
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=(A[i]//mid) -1
        else:
            numofcut+=A[i]//mid
    
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    mid=max((left+right)//2,1)
    if mid==1:
        break
print(mid)

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


def is_ok(i):
    su = 0
    for a in A:
        su += (a-1) // i
    if su <= K:
        return True
    else:
        return False

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

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

Solution (Python):
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
def ok(x):
  c=0
  for i in a:
    c+=0--i//x
  return c<=n+k
l,r=0,10**9
while r-l>1:
  m=l+r>>1
  if ok(m): r=m
  else: l=m
print(r)

Solution (Python):
N, K = map(int, input().split())

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


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


def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

def calc(length):
	count = 0
	for a in A_list:
		if a > length:
			if a % length == 0:
				count += (a // length) - 1
			else:
				count += a // length
	return count

print(auto_bisearch_smallest(lambda length: calc(length) <= K, 1))

Solution (Python):

import sys
import math
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()))
lst1.sort(reverse=True)
def func(mid): 
    res = 0
    for i in range(n):
        if mid >= lst1[i]:
            continue
        res += math.ceil(lst1[i]/mid)-1
        if res > k:
            return False
    return True


def binary_search(): 
    ok = 10**9
    ng = 0
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid):
            ok = mid
        else:
            ng = mid

    return ok

print(binary_search())

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
import math
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7


def main():
    N, K = MAP()
    A = LIST()

    if K == 0:
        print(max(A))
        return

    
    left = 0
    right = 10**9+7
    for i in range(100):
        
        mid = (right + left) / 2
        count = 0
        for a in A:
            count += int(math.ceil(a / mid))-1
        if count <= K:
            right = mid
        else:
            left = mid
    print(int(math.ceil(left)))

    return


if __name__ == '__main__':
    main()

Solution (Python):
from math import floor

m=0
M=10**9+1

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

def OK(p):
    if sum([(a-1)//p for a in A])<=K:
        return True
    else:
        return False

while M-m>1:
    p=(m+M)//2
    if OK(p):
        M=p
    else:
        m=p
print(M)

Solution (Python):
import heapq
import math
import sys

input = sys.stdin.readline


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

    def C(m):
        cnt = 0
        for i in range(N):
            cnt += math.ceil(A[i]/m)-1
        return cnt

    l, r = 0, max(A)
    while r - l > 1:
        mid = (l+r)//2
        if C(mid) <= K:
            r = mid
        else:
            l = mid
    
    print(r)

if __name__ == "__main__":
    main()

Solution (Python):
import math

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

def check(L):
    return sum(math.ceil(a / L)-1 for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if ok: 
        answer=min(m, answer)
        hi=m
    else:
        lo=m+1
print(answer)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("../output.txt", "w")
except:
    pass







def pos(m):
    ans=0
    for ele in A:
        ans+=((ele-1)//m)
    return ans<=k

n,k=L()
A=L()
l=1
r=max(A)
ans=r
while(l<=r):
    m=(l+r)//2
    if pos(m):
        r=m-1
        ans=m
    else:
        l=m+1
print(ceil(ans))

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=max(a)
ng=0
while ok-ng>1:
    mid=(ok+ng)//2
    cnt=0
    for i in range(n):
        num=a[i]
        cnt+=-(-num//mid)-1
    if cnt<=k:
        ok=mid
    else:
        ng=mid
print(ok)

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

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



l=0
r=pow(10,11)
while r-l>1:
    
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            x=-(-a[i]//mid)-1
            cnt-=x

    
    if cnt>=0:
        r = mid  
    else:
        l = mid  

print(r)

Solution (Python):
from math import ceil
n, k, *A = map(int, open(0).read().split())
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
c = k - sum(int(a/t)-1 for a in A)
X = []
for a in A:
    X.append(ceil(a / ceil(a/t)))
    X.append(ceil(a / int(a/t)))
X.sort()
print(X[-c-1])

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


low=0
high=10**9+1

while low<=high:
    mid=(low+high)//2
    if mid==0: 
        print(1)
        exit()

    cnt=0
    for a in A:
        v=ceil(a/mid)
        cnt+=v-1

    if cnt<=K:
        high=mid-1
    else:
        low=mid+1
print(low)

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

left = 0
right = max(A) + 1

while left+1!=right:
  mid = (left + right)//2
  x = 0
  for a in A:
    x += math.ceil(a/mid) - 1
  if x<=K:
    right = mid
  else:
    left = mid
  
print(right)

Solution (Python):
import math

def main():
    _, k = map(int, input().split())
    arr = list(map(int, input().split()))
    l, r = 1, 1000000000
    while l < r:
        m = (l + r) // 2
        cnt = 0
        for val in arr:
            cnt += math.ceil(val / m) - 1
        if cnt > k:
            l = m + 1
        else:
            r = m
    print(l)
  
if __name__ == '__main__':
    main()

Solution (Python):
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 = (sum(A)/(len(A)+K))
for i, a in enumerate(A):
    cut_at_least = (math.floor(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
    if k <= N:
        heapq.heappush(hq, (-A[i]/(cuts[i]+1), i))
l, i = heapq.heappop(hq)
print(math.ceil(-l))

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

def is_ok(arg):
  
  
  cnt = 0
  for a in A:
    cnt += ceil(a / arg) - 1
  return cnt <= 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

ng = 0
ok = 10**9 + 1

ans = meguru_bisect(ng,ok)
print(ceil(ans))

Solution (Python):
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

low = 1
high = max(A)

while low < high:
    mid = (low + high) // 2

    k = 0
    for a in A:
        v = a // mid
        if a % mid == 0:
            v -= 1
        k += v

    if k <= K:
        high = mid
    else:
        low = mid + 1

print(low)

Solution (Python):
import heapq as hq

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

cnt = [0]*n

a_sum = sum(a)
for i in range(n):
    cnt[i] = k*a[i]//a_sum

cnt_sum = sum(cnt)
r = k - cnt_sum
l = []

for i in range(n):
    hq.heappush(l, (-a[i]/(cnt[i]+1), i))

for _ in range(r):
    x,i = hq.heappop(l)
    cnt[i] += 1
    hq.heappush(l, (-a[i]/(cnt[i]+1), i))

x,i = hq.heappop(l)
print(int(x // 1 * -1))

Solution (Python):

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>2:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
mid-=1
if mid<=0: mid=1
while True:
    temp=0
    flag=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: mid+=1
    else:
        flag=1
        break
    if flag: break
print(mid)

Solution (Python):
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from heapq import heapify, heappop, heappush

from math import ceil, log, floor
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, k = sp()
arr = L()
low, high = 1, max(arr)
answer = max(arr)
while low <= high:
    mid = (low + high) >> 1
    req = 0
    for i in range(n):
        if arr[i] <= mid:
            continue
        else:
            temp = arr[i] // mid
            req += temp
    if req <= k:
        answer = min(answer, mid)
        high = mid - 1
    else:
        low = mid + 1
out(answer)

Solution (Python):
import sys
import math

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(ok, ng):
        """
        is_okを定義して下さい
        :param ok: 取りうる最小の値-1
        :param ng: 取りうる最大の値+1
        :return: is_okを満たす最小(もしくは最大)の値
        """
        while abs(ok - ng) > 10 ** -5:
            mid = (ok + ng) / 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def is_ok(x):
        cnt = 0
        for i in range(n):
            if A[i] > x:
                cnt += (A[i] + x - 1) // x - 1

        return cnt <= k

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

    res = meguru_bisect(10 ** 9 + 1, 0)
    print(math.ceil(res))


if __name__ == '__main__':
    resolve()

Solution (Python):
from math import ceil

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

def is_ok(n):
    t = 0
    for a in A:
        if a <= n:
            continue
        t += ceil(a / n) - 1
    return t <= K

ok = 1000000000
ng = 0.0000000001
while abs(ng - ok) > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(ceil(ok))

Solution (Python):
N,K=map(int,input().split())
L=list(map(int,input().split()))
    
import math
MAX=10**9
MIN=0
for i in range(100):
    Mid=(MAX+MIN)/2
    cnt=0
    for j in range(N):
        cnt+=L[j]//Mid
    if cnt<=K:
        MAX=Mid
    else:
        MIN=Mid
    
print(math.ceil(Mid))

Solution (Python):
import math

from sys import stdin
input = stdin.readline


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

  if K == 0:
    print(max(A))
    return

  def solve(L):
    ncut = 0
    for i in range(N):
      ncut += (math.ceil(A[i]/L) - 1)
      
      if ncut > K:
        return False
    return True

  ok = 10**9
  ng = 0
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    bool_ = solve(mid)
    
    if bool_:
      ok = mid
    else:
      ng = mid

  print(ok)


if(__name__ == '__main__'):
  main()

Solution (Python):
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
try:
  up, lo = ceil(sum(A) / K), 0
  while up - lo > 1:
    mid = (up+lo) // 2
    cnt = 0
    for a in A:
      cnt += ceil(a / mid)-1
    if cnt > K:
      lo = mid
    else:
      up = mid
  print(up)
except ZeroDivisionError:
  print(max(A))

Solution (Python):
import sys
input = sys.stdin.readline
import math

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N, K = MI()
mylist = LI()
length = len(mylist)

high = max(mylist)+1
low = 0
mid = (high + low) / 2

while high - low >= 0.001:
    temp = 0
    for i in mylist:
        if i % mid == 0:
            temp += (i // mid) - 1
        else:
            temp += i // mid
    if temp > K:
        low = mid
    else:
        high = mid
    mid = (high + low) / 2

result = math.ceil(low)


num2 = result+10**(-8)
temp= 0
for i in mylist:
    if i % num2 == 0:
        temp += (i // num2) - 1
    else:
        temp += i // num2
if temp > K:
    print(result+1)
else:
    print(result)

Solution (Python):
from math import *
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
def ok(x):
  c=0
  for i in a:
    c+=ceil(i/x)
  return c<=n+k
l,r=0,10**9
while r-l>1:
  m=(l+r)/2
  if ok(m): r=m
  else: l=m
t=ceil(r)
print(t-ok(t-1) if t>1 else t)

Solution (Python):
import sys

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


def is_ok(x):
    num = 0
    for j in range(N):
        num += (A[j] - 1) // x

    if num <= 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))

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
left=1
right=A[-1]
ans=(left+right)//2
if N==1:
    if A[0]%(K+1)==0:
        print(A[0]//(K+1))
    else:
        print(A[0]//(K+1)+1)
else:
    while 1:
        count=0
        for i in range(N)[::-1]:
            if A[i]%ans==0:
                count+=A[i]//ans-1
            else:
                count+=A[i]//ans
            if count>K:
                break
        if count<=K:
            right=ans
        else:
            left=ans
        if right-left<=1:
            break
        ans=(left+right)//2
    for i in range(N):
        if A[i]%left==0:
            count+=A[i]//left-1
        else:
            count+=A[i]//left
        if count>K:
            break
    if count<=K:
        print(left)
    else:
        print(right)

Solution (Python):
n,k=map(int,input().split())
arr=list(map(int,input().split()))
m=max(arr)
if(k==0):
	print(m)
else:
	low=1
	high=m
	while(low<=high):
		mid=low+(high-low)//2
		if(mid==1):
			print(mid)
			break
		count=0
		count2=0
		for i in range(n):
			count+=(arr[i]-1)//mid
			count2+=(arr[i]-1)//(mid-1)
		if(count<=k and count2>k):
			print(mid)
			break
		elif(count<k or (count<=k and count2<=k+1)):
			high=mid-1
		else:
			low=mid+1

Solution (Python):
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)


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

Solution (Python):
n, k = map(int, input().split())
As = list(map(int, input().split()))


def solve(t):
    count = 0
    for a in As:
        if a % t == 0:
            count += a // t - 1
        else:
            count += a // t
    if count <= k:
        return True
    else:
        return False


def main(l, r):
    if r - l == 1:
        print(r)
    else:
        m = (l + r) // 2
        if solve(m):
            r = m
            return main(l, r)
        else:
            l = m
            return main(l, r)

if solve(1):
  print('1')
else:
  main(1, max(As))

Solution (Python):
import sys
from operator import itemgetter
def dhondt(Votes, n_seats):
    
    n_candidates = len(Votes)
    sum_votes = sum(Votes)
    S0 = []  
    C = []
    for i, v in enumerate(Votes):
        s0 = n_seats*v//sum_votes
        S0.append(s0)
        for s in range(s0+1, s0+10000):
            if s*sum_votes >= v*(n_seats+n_candidates):
                break
            C.append((s/v, i))
        else:
            assert False
    C.sort(key=itemgetter(0))
    S = S0[:]
    for _, i in C[:n_seats-sum(S0)]:
        S[i] += 1
    return S0, S


input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
sum_A = sum(A)
S0, S = dhondt(A, K)
ans = 0
for s, a in zip(S, A):
    ans = max(ans, -(-a//(s+1)))
print(ans)

Solution (Python):
from math import *
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
def ok(x):
  c=0
  for i in a:
    c+=ceil(i/x)
  return c<=n+k
l,r=0,10**9+1
while r-l>0.1:
  m=(l+r)/2
  if ok(m): r=m
  else: l=m
t=ceil(r)
print(t-ok(t-1) if t>1 else t)

Solution (Python):
from math import ceil

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

l_lb, l_min = 0, max(A)
while l_min - l_lb > 1:
  l_mid = (l_lb + l_min) // 2
  if sum(ceil(a/l_mid) for a in A) - N > K:
    l_lb = l_mid
  else:
    l_min = l_mid
print(l_min)

Solution (Python):
from math import ceil
n,k=map(int,input().split())
lst=list(map(int,input().split()))
ng=0
ok=10**9+1
while ok-ng>1:
    mid=(ok+ng)//2
    tmp=0
    for i in range(n):
        tmp+=ceil(lst[i]/mid)-1
    if tmp>k:
        ng=mid
    else:
        ok=mid
print(ok)

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

if __name__ == '__main__':
    resolve()

Solution (Python):
import math
import heapq
n,k=map(int,input().split())
a=list(map(int,input().split()))
SUM=sum(a)
ans=[]
y=k

for i in range(n):
    x=a[i]*k//SUM
    ans.append([-math.ceil(a[i]/(1+x)),x,i])
    y-=x

heapq.heapify(ans)


for i in range(y):
    temp=heapq.heappop(ans)
    temp[0]=-math.ceil(a[temp[2]]/(2+temp[1]))
    temp[1]+=1
    heapq.heappush(ans,temp)

temp=heapq.heappop(ans)
print(-temp[0])

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

hi = 10**18
lo = 0

while hi - lo > 1:
    mid = (hi + lo) // 2
    cut = 0
    for i in range(N):
        cut += (A[i] + mid - 1) // mid - 1
    if cut <= K:
        hi = mid
    else:
        lo = mid

print(hi)