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):
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


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


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


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

Solution (Python):
import copy
import math

def calc(x, aa):
    a = copy.deepcopy(aa)
    cnt = k
    while cnt > 0:
        for i in range(n):
            if (a[i] > x):
                cnt -= a[i] // x
                a[i] = x
            if cnt < 0:
                return False
        if cnt < 0:
            return False
        return True
    
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
left, right = 0, max(a)
if k == 0:
    print(right)
    exit()
    
while (right - left) > 1:
    middle = (left + right) / 2
    if calc(middle, a):
        right = middle
    else:
        left = middle        
for i in range(max(math.floor(left) - 10, 1), math.ceil(right) + 10):
    if calc(i, a):
        print(i)
        exit()

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



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


print(dai)

Solution (Python):
def get_cuts_nr(loglens, ln):
    ans = 0
    for log in loglens:
        ans += (log - 1) // ln
    
    return ans

def solvee():
    n, k = (int(x) for x in input().split())
    loglens = [int(x) for x in input().split()]

    l_op = 0
    r_cl = 10 ** 9 + 5
    while r_cl - l_op > 1:
        m = (l_op + r_cl) // 2
        cuts_nr = get_cuts_nr(loglens, m)
        if cuts_nr > k:
            l_op = m
        else:
            r_cl = m
    
    print(r_cl)


if __name__ == '__main__':
    solvee()

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


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




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

Solution (Python):
n, k = map(int, input().split())
arr = [int(j) for j in input().split()]

s, e = 1, 100000000000

while s <= e:
   
    mid = (s+e)//2
    temp = 0
    for x in arr:
        temp += x//mid
        if x%mid == 0:
            temp -= 1
    
    if temp <= k:
        ans = mid
        e = mid-1
    else:
        s = mid+1

print(ans)

Solution (Python):
import math


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


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


left = 0
right = 10 ** 9 + 1

while int(left) != int(right):
    m = (left + right) / 2

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


print(math.ceil(m))

Solution (Python):
import math

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

K += N
sum_ = sum(a_list)

ideal_d = [(K / sum_) * a for a in a_list]
min_d = [math.floor(i_d) if math.floor(i_d) != 0 else 1 for i_d in ideal_d]

max_ded_a_list = [a/m_d for a, m_d in zip(a_list, min_d) ]
min_ded_a_list = [a/(m_d+1) for a, m_d in zip(a_list, min_d)]
num_replace = K - sum(min_d)
max_ded_a_list.sort(reverse=True)

ans = math.ceil(max_ded_a_list[num_replace])
print(ans)

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

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

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

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





N, K = getNM()
A = getList()






def f(target):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / target) - 1
    if cnt <= K:
        return True
    else:
        return False

ng = 0
ok = 10 ** 9 + 1
for i in range(100):
    mid = (ng + ok) / 2
    
    if f(mid):
        ok = mid
    
    else:
        ng = mid
print(math.ceil(ok))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N, K = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()]
    l, r = 0, max(A)
    def f(m):
        ret = 0
        
        for a in A:
            ret += (a // m) - 1 + (a % m > 0)
            if ret > K:
                return False
        return True

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

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
import numpy as np
import math

setrecursionlimit(10 ** 7)

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

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

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

while point <= 100:
    ave = (hi+low)/2
    if np.ceil(a//ave).sum() <= k:
        hi = ave
    else:
        low = ave
    point += 1

print(math.ceil(ave))

Solution (Python):
BIG = 10**10

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



def solve(x):
    m = 0
    for a in A:
        m += -(-(a//x))
    
    return m > K

A = [a*BIG for a in A]


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



print(-(-ok//BIG))

Solution (Python):


import math


def solve(n):
    cnt = 0
    for i in a:
        if i % n == 0:
            cnt += i // n - 1
        else:
            cnt += i // n
    if cnt <= k:
        return True  
    else:
        return False


n, k = map(int, input().split())
a = [int(_) for _ in input().split()]
ng = 0  
ok = 10 ** 9 + 1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(ok)

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

from math import ceil

def f(length):
  rtn = 0
  for i in range(n):
    rtn += ceil(a[i]/length) - 1
  return rtn

if f(1) == 0:
  print(1)
else:
  while ok - ng > 1:
    mid = (ok + ng)//2
    if f(mid) <= k:
      ok = mid
    else:
      ng = mid

  if f(ng) > k:
    print(ok)
  else:
    print(ng)

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



ok=max(A)
ng=0

def isok(t):
  res=0
  for i in range(N):
    res+=A[i]//t-(A[i]%t==0)
  return res<=K

while abs(ok-ng)>1:
  mid=(ok+ng)//2
  if isok(mid):
    ok=mid
  else:
    ng=mid

print(ok)

Solution (Python):
import math
import sys
input = sys.stdin.readline
INF = float("inf")


def isOK(m, K, arr):
    cnt = 0
    for a in arr:
        if a > m:
            cnt += a // m
    return cnt <= K


def binary_search(ok, ng, K, arr=[]):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid, K, arr):
            ok = mid
        else:
            ng = mid
    return ok



def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    ok = 10**9
    ng = 0
    ans = binary_search(ok, ng, K, A)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
I=lambda:list(map(int,input().split()))
n,k=I()
l=I()
low=1
high=max(l)
while low<high:
	mid=(low+high)//2
	temp=0
	for i in l:
		temp+=(i//mid)-(i%mid==0)
	if temp>k:
		low=mid+1
	else:
		high=mid
print(low)

Solution (Python):
import sys
from bisect import bisect_right
from math import ceil
def input(): return sys.stdin.readline().strip()


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

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



if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
alist = list(map(int, input().split()))
import math
K += N
sum_ = sum(alist)
ideal_denom = [(K / sum_) * a for a in alist]
min_denom = [math.floor(i_d) if math.floor(i_d) != 0 else 1 for i_d in ideal_denom]
max_denomed_alist = [a/m_d for a, m_d in zip(alist, min_denom) ]
min_denomed_alist = [a/(m_d+1) for a, m_d in zip(alist, min_denom)]

num_replace = K - sum(min_denom)

max_denomed_alist.sort(reverse=True)
ans = math.ceil(max_denomed_alist[num_replace])
 

print(ans)

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

l = 0
r = max(A) + 1

while(l+1<r):
    m = (l+r)//2
    count = 0
    for a in A:
        count += (a-1) // m
    
    if count > K:
        l = m
    else:
        r = m
print(r)

Solution (Python):
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
def solve(x):
    kk = k
    for i in a:
        kk -= (i+x-1)//x - 1
    return kk>=0

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

Solution (Python):
import math

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

    l = 0
    r = 10**9

    while (r - l) >= 10**(-6):
        m = (l + r) / 2
        t = 0
        for A in As:
            t += math.ceil(A / m - 1)
            if t > K:
                break

        if t <= K:
            l, r = l, m
        else:
            l, r = m, r

    print(math.ceil(l))

main()

Solution (Python):
import heapq
from decimal import *
import math

def binary_search(left: int, right: int, check_func, search_max:bool=False):
    
    while abs(right - left) > 1:
        mid = (left + right) // 2
    
        if check_func(mid) ^ search_max:
            right = mid
        else:
            left = mid

    return left if search_max else right

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

    def isOK(x):
        b = sum([(a - 1) // x for a in A])

        return b <= K

    ans = binary_search(0, 10 ** 9, isOK)
    print(ans)

if __name__ == '__main__':
    main()

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

def judge(x):
    k = 0
    for a in A:
        v = a // x
        if a % x == 0:
            v -= 1
        k += v
    return k <= K

low = 1
high = max(A)

A.sort()

while low < high - 1:
    mid = (low + high) // 2
    if judge(mid):
        high = mid
    else:
        low = mid

if judge(low):
    print(low)
else:
    print(high)

Solution (Python):
from math import *
def isok(x):
    res=0
    for i in range(N):
        if A[i]<=x:
            continue
        res+=floor(A[i]/x)
    if res<=K:
        return True
    else:
        return False

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

ng,ok=0,10**10

while(ok-ng>1):
    mid=(ok+ng)//2
    if isok(mid):
        ok=mid
    else:
        ng=mid
print(ok)

Solution (Python):
n,k=map(int, input().split())
a = list(map(int, input().split()))
a=sorted(a,reverse=True)
if k==0:
    print(max(a))
    exit()
import math
lo=0
hi=10**9
oldmid=0
while True:
    mid=(hi+lo)/2
    cnt=0
    for i in range(n):
        cnt+=round(a[i]/mid-0.5)
    if cnt>k:
        lo=mid
    elif cnt<=k:
        hi=mid
    if oldmid-0.000001<=(hi+lo)/2<=oldmid+0.000001:
        print(min(math.ceil(lo), max(a)))
        break
    oldmid=mid

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

OK = 10**9
NG = 0

while OK - NG > 1:
    ans = 0
    mid = (OK+NG)//2
    for a in A:
        ans += (a-0.1)//mid
    if ans > K:
        NG = mid
    else:
        OK = mid
print(OK)

Solution (Python):
import math
import heapq
def main():

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

    l, r = 1, max(A)
    valid = max(A)

    while l <= r:
        m = (l+r) // 2
        count = 0
        for v in A:
            count += (v-1) // m
        if count <= K:
            r = m-1
            valid = min(valid, m)
        else:
            l = m+1

    ans = max(A)
    for u in [valid+1, valid, max(1,valid-1)]:
        count = 0
        for v in A:
            count += (v-1) // u
        if count <= K:
            ans = u
    return ans

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

Solution (Python):
def ceil(n, m):
    return -(-n // m)


def possible(l, K):
    cut = 0
    if l <= 0:
        return False
    for i in range(N):
        cut += ceil(A[i], l) - 1
        if cut > K:
            return False
    return True

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
L = sum(A)

ng = (L // (N + K)) - 1  
ok = max(A)

while ok - ng > 1:
    mid = (ok + ng) // 2
    if possible(mid, K):
        ok = mid
    else:
        ng = mid

print(ok)

Solution (Python):
import heapq
import math

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

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

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

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

lo = 1
hi = max(a)


def ceildiv(a, b):
    return (a + b - 1) // b

def ok(x):
    cuts = 0
    for log in a:
        cuts += ceildiv(log, x) - 1

    if cuts <= k:
        return True

    return False

while lo < hi:
    mid = (lo + hi) // 2

    if ok(mid):
        hi = mid
    else:
        lo = mid + 1

print(lo)

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

def p(length): 
    if length == 0:
        return 1

    tmp = 0
    for a in A:
        if a % length == 0:
            tmp += (a // length) - 1
        else:
            tmp += a // length
        if tmp > K:
            return 0
    
    
    
    return 1
    

def bin_search(arr): 
    lb = 0
    ub = 1000000000

    while ub - lb > 1:
        mid = (ub + lb) // 2
        if p(mid) == 1:
            ub = mid
        else:
            lb = mid
    
    return lb

def just(num):
    if num == 0:
        return 0
        
    tmp = 0
    for a in A:
        if a % num != 0:
            return 0
        else:
            tmp += a // num
    if tmp != K:
        return 0
    else:
        return 1

ans_tmp = bin_search(A)
if just(ans_tmp) == 1:
    print(ans_tmp)
else:
    print(ans_tmp + 1)

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

print(ub)

Solution (Python):
from math import ceil
def C(x):
  cnt = 0
  for i in range(n):
    cnt += ceil(a[i] / x) - 1
  if cnt > k:
    return False
  else:
    return True
  
n, k = map(int, input().split())
a = list(map(int, input().split()))
lb = 0
ub = 1000000000
while ub - lb > 1:
  mid = (lb + ub) // 2
  if C(mid):
    ub = mid
  else:
    lb = mid
print(ub)

Solution (Python):
from heapq import heappush, heappop, heapify

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


def check(x):
    
    
    cnt = sum([(ai - 1) // x for ai in a])
    return cnt <= k


lb = 0  
ub = max(a)  
while ub - lb > 1:
    mid = (ub + lb) // 2
    
    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal, ROUND_CEILING
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 zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, K = MAP()
A = LIST()

l = 0
r = 10**9+1
while l+1 != r:
    m = (l+r)//2
    cnt = 0
    for L in A:
        cnt += 0--L//m-1
        if cnt > K:
            ret = False
            break
    else:
        ret = True

    if ret:
        r = m
    else:
        l = m
print(l+1)

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


def C(x):
    return sum([max((Ai + x - 1) // x - 1, 0) for Ai in A])


A.sort()
left = 1
right = A[-1]
while left + 1 < right:
    mid = (left + right) // 2
    S = C(mid)
    if S <= K:
        right = mid
    else:
        left = mid
print(left if C(left) <= K else right)

Solution (Python):
from bisect import bisect_left,bisect
import math

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

m = 0
M = max(A) + 1

while M - m > 1:
  temp = (M + m) // 2
  L = bisect(A, temp)
  cnt = 0
  for i in range(L, N):
    p, q = divmod(A[i], temp)
    if q == 0:
      cnt += p-1
    else:
      cnt += p
  if cnt > K:
    m = temp
  else:
    M = temp

print(M)

Solution (Python):
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

n,k=I()
l=I()
lo=1;hi=max(l)
while lo<hi:
	md=(lo+hi)//2
	ct=0
	for i in range(n):
		ct+=l[i]//md-(l[i]%md==0)
	if ct<=k:
		hi=md
	else:
		lo=md+1
print(lo)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

n,k = na()
a = na()

def is_ok(arg):
    if arg == 0: return False
    j = 0
    for i in a:
        j += math.ceil(i/arg)-1
        if j > k:
            return False
    return True

ok = max(a)
ng = 0
while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

print(ok)

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

def test(m):
    if m <= 0:
        return False
    needed = 0
    for a in A:
        needed += (a-1)//m
        if needed > K:
            return False
    return True

lb = 1
ub = max(A)

while True:
    m = (lb + ub) // 2
    if test(m):
        if test(m-1):
            ub = m - 1
        else:
            print(m)
            exit()
    else:
        lb = m + 1

Solution (Python):
import sys
import heapq

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    def isOK(mid):
        cnt = 0
        for i in range(N):
            if A[i] > mid:
                cnt += -(-A[i] // mid) - 1
                if cnt > K:
                    return False
        return True

    ok = max(A)
    ng = 0

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()

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
    while right - left > 1.0e-6:
        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):
import sys
input = sys.stdin.readline
import math


def read():
    N, K = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, K, A


def solve(N, K, A):
    if N == 1:
        if K == 0:
            return A[0]
        else:
            return math.ceil(A[0] / (K+1))
    ng = 0
    ok = max(A)
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        k = sum([(a-1) // mid for a in A])
        if k <= K:
            ok = mid
        else:
            ng = mid
    return ok


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

l = 0
r = max(A)+1

while(l+1 < r):
    m = (l+r)//2
    tmp = 0
    for a in A:
        tmp += math.ceil(a / m)-1
    if tmp <= K:
        r = m
    else:
        l = m

print(r)

Solution (Python):
n,k = map(int, raw_input().split())
ais = map(int, raw_input().split())

def p(m,ais,k):
	t = [ m, ais, k]
	for ai in ais:
		if ai > m:
			k-= ai / m
	return k >=0

lo,hi = 1, max(ais)

while(lo < hi):
	med = (lo + hi)/2
	if p(med, ais, k):
		hi = med
	else:
		lo = med + 1

print lo

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

def calc(n):
    num = K
    for a in A:
        s = max(a // n, 1)
        for cnt in range(s, a):
            if a / cnt <= n:
                num -= cnt - 1
                break
        if num < 0:
            return False
    return True


while end - start > 1:
    mid = (end + start) // 2
    if calc(mid):
        end = mid
    else:
        start = mid

print(end)

Solution (Python):
def is_ok(mid):   
    global N, K, A
    cnt = 0
    flag = True
    for i in range(N):
        if A[i] <= mid:
            break
        if cnt + A[i] // mid > K:
            flag = False
            break
        cnt += A[i] // mid
    if flag:
        return True
    return False

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

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

Solution (Python):
import math

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

l = 1
r = 10**9+1

while l < r:
    mid = (l+r)//2
    count = 0
    for i in range(n):
        if A[i] > mid:
            count += math.ceil(A[i]//mid)

    if count <= k:
        r = mid
    else:
        l = mid+1


print(l)

Solution (Python):
import copy
import math

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

ub = 10**9
lb = 0

while ub - lb > 10**-6:
    x = (ub + lb) / 2
    cnt = 0
    for i in a:
        cnt += math.ceil(i/x)
    if cnt <= n+k:
        ub = copy.deepcopy(x)
    else:
        lb = copy.deepcopy(x)
ans = round(ub, 6)
print(math.ceil(lb))

Solution (Python):
import math
def is_ok(mid,k):
  cnt=0
  for i in a:
    cnt+=max(int((i-0.1)/mid),0)
  if cnt<=k:return 1
  else:return 0
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
ng=0
ok=a[-1]
while abs(ng-ok)>0.0001:
  mid=(ng+ok)/2
  if is_ok(mid,k):ok=mid
  else:ng=mid
print(math.ceil(ok))

Solution (Python):
from math import ceil, floor
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10**9
m = (l+r)//2+1
for i in range(100):
    
    cnt = 0
    for j in a:
        cnt += (ceil(j/m)-1)
    
    
    if cnt <= k:
        r = m
        m = ceil((l+r)/2)
    else:
        l = m
        m = ceil((l+r)/2)
print(m)

Solution (Python):

from math import ceil

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


def f(p):
    c = 0
    for x in a:
        c += x // p
    return c


ok, ng = 0, max(a) + 1
while abs(ok - ng) > 3e-6:
    m = (ok + ng) / 2
    if f(m) > k:
        ok = m
    else:
        ng = m
print(ceil(ok))

Solution (Python):
import math

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

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


def judge(x):
    k = 0
    for a in A:
        if a <= x:
            continue
        if a % x == 0:
            k += a // x - 1
        else:
            k += a // x
    if k <= K:
        return True
    else:
        return False


def solve():
    left, right = 0, max(A)
    while right - left > 1:
        x = (left + right) // 2
        if judge(x):
            right = x
        else:
            left = x
    return right


def main():
    ans = solve()
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


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
    d=K/N
    K_i=[int(A[i]/aveA*d) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()

Solution (Python):
import sys
import math

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

left = 0  
right = 10 ** 9 + 1  


def judge(length, num_cut):
    cut = 0
    for a in A:
        if a > length:
            cut += math.ceil(a / length) - 1

    if cut <= num_cut:
        return True

    return False


while right - left > 1:
    mid = (left + right) // 2
    

    if judge(mid, K):
        right = mid
    else:
        left = mid

print(right)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
def f(x):
    global a,n,k
    if x==0:
        return 10**10
    ret=0
    for i in range(n):
        
        ret+=(-((-a[i])//x)-1)
    return ret

l,r=0,10**10
while l+1<r:
    x=l+(r-l)//2
    if f(x)<=k:
        r=x
    else:
        l=x

print(r)

Solution (Python):
from math import ceil

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

def flag(upper):
    c = 0
    for a in A:
        c += ceil(a / upper) - 1
        if c > k:
            return False
    return True

def main():
    A.sort(reverse=True)
    low = 1
    high = A[0]
    while low < high:
        mid = (low + high) // 2
        if flag(mid):
            high = mid
        else:
            low = mid + 1
    print(high)
    return

if __name__ == "__main__":
    main()