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 as m


def binary_search_int(f, start, stop):
    """
    Binary search for the point at which f() becomes false

    f() may be evaluated at the points in [start, stop) half-open
    The return value will be in the range [start, stop] inclusive

    f() must be always true to the left of some point, and always false to the right

    >>> f = lambda x: x <= 50
    >>> binary_search_int(f, 40, 91)
    51
    >>> binary_search_int(f, 20, 31)
    31
    >>> binary_search_int(f, 60, 81)
    60
    """
    assert start < stop

    left, right = start, stop
    while left < right:
        mid = (left + right)//2
        if f(mid):
            left = mid+1
        else:
            right = mid

    return right


def binary_search_float(f, left, right, rel_tol=1e-09, abs_tol=0.0):
    """
    Binary search for the point at which f() becomes false

    f() must be always true to the left of some point, and always false to the right

    Note: If the return may be close to 0, set abs_tol to avoid excessive/infinite iteration

    >>> f = lambda x: x < 3.5
    >>> _ = binary_search_float(f, 0, 10)
    >>> round(_, 6)
    3.5
    """
    assert left <= right

    while not m.isclose(left, right, rel_tol=rel_tol, abs_tol=abs_tol):
        mid = (left + right)/2
        if f(mid):
            left = mid
        else:
            right = mid

    return right


def ternary_search_int(f, start, stop):
    """
    Ternary search for the maximum point of f()

    df/dx must be always positive to the left of some point, and always negative to the right

    >>> f = lambda x: -(x-42)**2
    >>> ternary_search_int(f, 0, 100)
    42
    """
    assert start < stop

    invphi2 = (3-m.sqrt(5)) / 2

    a, d = start, stop-1
    b = a + round(invphi2 * (d-a))
    c = b + m.ceil(invphi2 * (d-b))
    fb = f(b)
    fc = f(c)

    while True:
        if fb < fc:
            if c == d: return d
            a = b+1
            b, fb = c, fc
            c = b + m.ceil(invphi2 * (d-b))
            fc = f(c)
        else:
            if a == b: return a
            d = c-1
            c, fc = b, fb
            b = c - m.ceil(invphi2 * (c-a))
            fb = f(b)


def ternary_search_float(f, left, right, rel_tol=1e-09, abs_tol=0.0):
    """
    Ternary search for the maximum point of f()

    df/dx must be always positive to the left of some point, and always negative to the right

    Note: If the return may be close to 0, set abs_tol to avoid excessive/infinite iteration

    >>> f = lambda x: -(x-3.5)**2
    >>> _ = ternary_search_float(f, 0, 10)
    >>> round(_, 6)
    3.5
    """
    assert left <= right

    invphi2 = (3-m.sqrt(5)) / 2

    a, d = left, right
    b = a + invphi2 * (d-a)
    c = b + invphi2 * (d-b)
    fb = f(b)
    fc = f(c)

    while not m.isclose(a, d, rel_tol=rel_tol, abs_tol=abs_tol):
        if fb < fc:
            a = b
            b, fb = c, fc
            c = b + invphi2 * (d-b)
            fc = f(c)
        else:
            d = c
            c, fc = b, fb
            b = c - invphi2 * (c-a)
            fb = f(b)

    return c



if False:  
    import doctest
    doctest.testmod()





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

def ceildiv(a, b):
    q, r = divmod(a, b)
    return q + bool(r)

def impossible(x):
    cost = sum(ceildiv(a, x)-1 for a in A)
    return cost > K

print(binary_search_int(impossible, 1, int(1e9)))

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

num = n + k
count = 0
s = 0
l = max(a)
while True:
    count = 0
    mid = (s + l) / 2
    for i in range(n):
        if a[i] % mid == 0:
            count += a[i] // mid
        else:
            count += a[i] // mid + 1
    if count > num:
        s = mid
    else:
        l = mid
    temp = (s + l) / 2
    if abs(mid - temp) < 0.001:
        break
if mid == int(mid):
    print(int(mid))
else:
    print(int(mid) + 1)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



def ceil(a,b):
    return a//b + int(a%b != 0)

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

ok = max(A)
ng = 0

while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    count = 0
    for i in range(N):
        count += ceil(A[i],mid)-1
    if count <= K:
        ok = mid
    else:
        ng = mid

print(ok)

Solution (Python):

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

ub = 10 ** 9 + 7
lb = 0
while ub - lb > 1:
    mid = (ub + lb) // 2

    res = 0
    for v in X:
        res += (v - 1) // mid

    if res <= K:
        ub = mid
    else:
        lb = mid

if K == 0:
    print(max(X))
else:
    print(ub)

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


a.sort()

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

def solve(num):
    ret=0
    for tmp in a:
        ret+= tmp//num
        if tmp%num==0:
            ret-=1
    return k>=ret

l=0
r=10**18
while r-l>1:
    mid=(l+r)//2

    if solve(mid):
        r=mid
    else:
        l=mid

print(min(max(a),r))

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

left = 0
right = 10**9 + 1

while right - left > 1:
    mid = (right + left) // 2
    cnt = 0
    for b in a:
        cnt += b // mid + int(b % mid != 0) - 1
    if cnt <= k:
        right = mid
    else:
        left = mid
print(right)

Solution (Python):
def cut(N):
    if N % r == 0:
        return N // r - 1
    else:
        return N // r
def solve(l):
    global r
    r = l
    b = list(map(cut, a))
    if sum(b) > k:
        return False
    else:
        return True
n, k = map(int, input().split())
a = list(map(int, input().split()))
u = max(a)
s = 0
while s + 1 < u:
    if solve((u + s) // 2):
        u = (u + s) // 2
    else:
        s = (u + s) // 2
print(u)

Solution (Python):
import math
def is_ok(mid,K,A):
    p = 0
    for i in A:
        p += (i - 1)// mid
    if p > K:
        return False
    else:
        return True
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
A.sort()
maxi = A[0]

ng = 0
ok = 10 ** 9
while(abs(ng - ok) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid,K,A):
        ok = mid
    else:
        ng = mid
print(ok)

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
high=max(A)
low=0
while high-low>1:
    cnt=0
    now=(low+high)//2
    for a in A:
        cnt+=max((a-1)//now,0)
        if cnt>k:
            break
    if cnt>k:
        low=now
    else:
        high=now
    
print(high)

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

max_a = 10**9
min_a = 0
while True:
    k = K
    res = (max_a+min_a)//2
    for i in range(N):
        if a[i] <= res:
            continue
        k -= (a[i]//res)
    if k >= 0:
        max_a = res
    else:
        min_a = res
    if max_a - min_a == 1:
        break
print(max_a)

Solution (Python):
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

"""
目標とする最長の長さをxとして、それをk回で達成
できるか
aをソートしたので、途中でkを超えることが判明したら打ち切る
"""

def isOK(x):
    cnt = 0
    for _a in a:
        if _a<=x:
            return True
        try:
            cnt+=_a//x
        except:
            return False
        if cnt>k:
            return False
    return True

ng = 0
ok = 10**9+1

while abs(ng-ok)>0.1:
    mid = (ng+ok)/2
    if isOK(mid):
        ok = mid
    else:
        ng = mid
    if ok < 1:
        break
ok = ceil(ok)
if isOK(ok-1):
    print(ok-1)
else:
    print(ok)

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

X = list(range(1,N+1))
lo = 1
hi = max(A)

while hi-lo>=2:
    mid = (lo+hi)//2
    
    temp = list(map(lambda x:  x//mid - (x%mid==0) ,A))
    if sum(temp) <= K:
        hi = mid
    else:
        lo = mid

temp = list(map(lambda x:  x//lo - (x%lo==0) ,A))

if sum(temp) <= K:
    print(lo)
else:
    print(hi)

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


def isOk(m):
    k = 0
    for a in A:
        if a > m:
            k += a//m
            if a % m == 0:
                k -= 1
    if k <= K:
        return True
    else:
        return False


l, r = 10**19, 1
while abs(r-l) > 1:
    m = (l+r)//2
    if isOk(m):
        l = m
    else:
        r = m

if isOk(r):
    print(r)
else:
    print(l)

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

l = 1
h = a[0]
while l != h:
    m = (l + h) // 2
    cut = 0
    for x in a:
        cut += x // m + (x % m != 0) - 1
    if cut <= k:
        h = m
    else:
        l = m + 1

print(l)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
maxa = max(As)

l, r = 0, maxa+1
while r-l>1:
    half = (l+r)//2
    cnt = 0
    for a in As:
        cnt += -(-a//half)-1
    if cnt>K:
        l = half
    else:
        r = half

print(r)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

ok=max(a)
ng=0

while ok-ng>1:
  m=(ok+ng)//2

  num=0
  for i in a:
    if i%m!=0:
      num+=(i//m)
    else:
      num+=(i//m)-1

  if num<=k:
    ok=m
  else:
    ng=m

print(ok)

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


x0, x1 = 0, 10**9
while x0+1 < x1:
    x = (x0+x1)//2
    s = sum((a-1)//x for a in A)
    
    if s > K:
        x0 = x
    else:
        x1 = x

print(x1)

Solution (Python):
n,k = map(int, input().split())
a = list(map(int, input().split()))
start = 1
end = max(a)
bs = 1
be = max(a)
while start != end:
    center = (start+end)//2
    tnp = 0
    for i in range(n):
        tnp += (a[i]-1)//center
    
    if (tnp>k):
        start = center
    else:
        end = center
    if (start==bs and end==be):
        x = 0
        for j in range(n):
            x += (a[j]-1)//start
        y = 0
        for j in range(n):
            y += (a[j]-1)//end
        
        
        if (x<=k):
            print(start)
        else:
            print(end)
        exit()
    bs = start
    be = end
    
print(start)

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

"""
切る回数は広義単調減少になる
にぶたん
"""

def is_dekiru(L):
    cnt = 0
    for a in A:
        cnt += (a + L - 1) // L - 1
    return cnt <= K

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

print(ok)

Solution (Python):
def binary_search(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        cnt = 0
        for i in a:
            cnt += (i - 1) // m
        
        if cnt <= k:
            c2 = m
        else:
            c1 = m
        return binary_search(c1, c2)

n, k = map(int, input().split())
a = list(map(int, input().split()))
x = binary_search(0, 10 ** 9)
for i in range(x + 5, max(x - 5, 0), -1):
    cnt = 0
    for j in a:
        cnt += (j - 1) // i
    if cnt <= k:
        ans = i
print(ans if not k == 0 else max(a))

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

Solution (Python):
import sys


def c(a, k, x):
    cnt = 0
    for log in a:
        if log < x:
            continue
        if log % x == 0:
            cnt += log // x - 1
        else:
            cnt += log // x
        if cnt > k:
            return False
    return True


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    lb = 0
    ub = 11 ** 9
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if c(a, k, mid):
            ub = mid
        else:
            lb = mid
    print(ub)


if __name__ == "__main__":
    main()

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

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

def test(x):
    temp = 0
    for a in A:
        temp += (a-1)//x
    return temp <= K

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



print(binary_search_int(10**9+100,0,test))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = k
    for i in a:
        tmp = math.ceil(i / x)
        cnt -= tmp - 1
        if cnt < 0:
            return False
    return True

n, k = LI()
a = LI()
a.sort(reverse=True)
ok = sum(a)
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)

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

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

max_ng = 0
min_ok = 10**9
while min_ok-max_ng>1:
    tgt = (min_ok+max_ng)//2
    if check(tgt):
        min_ok = tgt
    else:
        max_ng = tgt

print(min_ok)

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

ll=0
rr=10**9+1
for _ in range(10**2):
  
  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)))

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

def is_ok(l):
    if l<=0: return False
    k = 0
    for a in A:
        k += a//l
        if a%l==0:
            k -= 1
        if k > K:
            return False
    return True

ok = 10**9+1
ng = -1
while ok - ng > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

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

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

l=1
r=10**9
import math
for i in range(100):
    temp=0
    m=(r+l)/2
    for j in a:
        temp+=j//m
    if temp<=k:
        r=m
    else:
        l=m

print(math.ceil(m))

Solution (Python):

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

l = 0
r = max(A)

while r-l != 1:

    m = (l+r)//2

    now = 0
    for i in range(N):
        if A[i] % m == 0:
            now += A[i] // m -1
        else:
            now += A[i] // m

    if now > K:
        l = m
    else:
        r = m

print (r)

Solution (Python):
import math
from functools import reduce
from collections import deque
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,k,*A = get_all_int()

    
    l = 0
    
    r = 10**9

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

        
        x = 0
        for a in A:
            
            x += (a+c-1)//c - 1
        
        

        if x <= k:
            
            r = c
        else:
            
            l = c

    print(r)

main()

Solution (Python):

def solve():
  N, K = [int(x) for x in input().split()]
  A = [int(x) for x in input().split()]
  s, l = 0, 10**9
  
  
  while s + 1 < l:
    x = (s + l) // 2
    
    c = 0
    for a in A:
      c += -(-a//x) - 1
    
    if c <= K:  
      l = x
    else:
      s = x
  return l
print(solve())

Solution (Python):
n,k=map(int,input().split())
a=[int(j) for j in input().split()]
a.sort(reverse=True)
def f(x):
    c=0
    for i in a:
        if i<x:
            break
        c+=-(-i//x)-1
        if c>k:
            return False
    return True
left=0
right=a[0]
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid
    else:
        left=mid
print(right)

Solution (Python):

import numpy as np
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
np_A=np.array(A)

def ch(np_A,ans):
    tmp=(np_A-1)//ans
    if np.sum(tmp)<=k:
        return True
    else:
        return False


low=1
high=max(A)
while low<high :
    mid=(high+low)//2
    if ch(np_A,mid):
        high=mid
    else:
        low=mid+1
print(high)

Solution (Python):
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
l = 0 
h = a[0]
def pos(b):
  c = 0
  for i in range(n):
    if a[i] <= b:
      break
    c += math.ceil(a[i]/b)-1
    if c > k:
      return False
  return True
while l+1 < h:
  m = (l+h)//2
  if pos(m):
    h = m
  else:
    l = m
print(h)

Solution (Python):


import re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy
import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

def to10(A):
    ret=0
    for a in range(len(A)-1,-1,-1):
        ret+=X[a]*2**(N-1-a)
    return ret

def f(m,K,A):
    cnt=0
    for a in A:
        cnt+=(a+m-1)//m-1
    return cnt<=K
N,K=inputintlist()
A=inputintlist()
l=0
r=max(A)
for a in range(60):
    m=(l+r)//2
    if m==0:
        break
    if f(m,K,A):
        r=m
    else:
        l=m
print(r)

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

def f(x):
    
    cnt = 0
    for a in As:
        
        cnt += int((a-0.01)/x)
        if cnt > k:
            return False
    
    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(l)+1)

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

def possible(l):
    if l==0:
        return False
    c = 0
    for i in range(N):
        if A[i]%l==0:
            n = A[i]//l-1
        else:
            n = A[i]//l
        c += n
    return c<=K

l = 0
r = max(A)
m = (l+r)/2
for i in range(32):
    pos = possible(m)
    if pos:
        r = m
    else:
        l = m
    m = (l+r)/2

if possible(int(m)):
    print(int(m))
else:
    print(ceil(m))

Solution (Python):
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:
    
    tmp=math.ceil(ai/x)
    chk+=tmp
  return chk<=n+k
l,r=0,max(a)
for _ in range(50):
  x=(l+r)/2
  if func(x):
    l,r=l,x
  else:
    l,r=x,r
x=(l+r)/2
print(math.ceil(x))

Solution (Python):
n,k=map(int,input().split())
a=[int(j) for j in input().split()]
a.sort(reverse=True)

def f(x):
    c=0
    for i in a:
        if i<x:
            break
        c+=-(-i//x)-1
        if c>k:
            return False
    return True



left=0
right=a[0]
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid
    else:
        left=mid
print(right)

Solution (Python):
ans,A,N,K = 0,0,0,0

def a():
    global ans,A,N,K
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    if K == 0:
        return max(A)

    def dividable(x):
        global ans,A,N,K
        ans = 0
        for a in A:
            if a % x == 0:
                ans += a // x - 1
            else:
                ans += a // x
        return ans <= K

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

print(a())

Solution (Python):
import sys
import math
def main():
  n, k = map(int, input().split())
  a = list(map(int, input().split()))
  lo = 1
  up = 10**9 + 1
  while up-lo != 1:
    mid = (up + lo)//2
    temp =  0
    for i in a:
      temp += math.ceil(i / mid)-1
    if temp <= k:
      up = mid
    else:
      lo = mid
  temp = 0
  for i in a:
    temp += math.ceil(i/lo)-1
  if  temp <= k:
    print(lo)
  else:
    print(up)
      

if __name__ == "__main__":
  main()

Solution (Python):
import math

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

left = 0
right = max(a)

while True:
  mid = (left + right) // 2
  
  if mid == 0:
    cnt = 10 ** 10
  else:
    cnt = 0
    for _a in a:
      cnt += math.ceil(_a / mid - 1)
  
  if cnt > k:
    left = mid
  else:
    right = mid
  
  if right - left <= 1:
    break

print(right)

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


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

    l = 0
    r = max(A)

    while l+1 < r:
        count = 0
        length = (l+r) // 2
        for a in A:
            count += (a-1) // length

        if count <= k:
            r = length
        else:
            l = length

    print(r)


if __name__ == "__main__":
    main()