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):
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum((a-1)//m for a in A): ng = m
    else: ok = m
print(ok)

Solution (Python):
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum(map(lambda a: (a-1)//m, A)): ng = m
    else: ok = m
print(ok)

Solution (Python):
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum([(a-1)//m for a in A]): ng = m
    else: ok = m
print(ok)

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

l = 0
r = max(a) + 1
ref = 0
ans = 10**9

while l + 1 < r:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = min(ans, now)
        ref = 0
        r = now
print(ans)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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













low = 0
high = max(A)

while high != low+1:
    mid = (low + high) // 2
    cut_cnt = 0
    
    
    for i in range(N):
        tmp = math.ceil(A[i] / mid)
        if tmp > 0:
            cut_cnt += tmp - 1
    if cut_cnt <= K:
        high = mid
    else:
        low = mid 
print(high)









"""
L > t, L - t



7,9

3.5, 3.5, 9

3.5, 3.5, 3, 3, 3

K = 1
7, 4.5, 4.5
K = 2
3.5, 3.5, 4.5, 4.5
K = 3
3.5, 3.5, 3, 3, 3

K = 4
2.3, 2.3, 2.3, 3,3,3

"""

Solution (Python):

import math

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




ok = max(A)
ng = 0




def hantei(p):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / p) - 1
        
    
    if(cnt > K):
        
        return 'ng'
    else:
        return 'ok'



def shisya(ans):
    if((ans - ans // 1) >= 0.5):
        return(int(ans//1+1))
    else:
        return(int(ans//1))   



while shisya(ok)-shisya(ng) > 1:
    
        
    mid = shisya((ok+ng)/2)
    
    
    if(hantei(mid) == 'ng'):
        ng = mid
    else:
        ok = mid
    


print(shisya(ok))

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

max_len = max(A)
def f(x):
    ans = 0
    for a in A:
        cut_num = math.ceil(a / x) - 1
        
        ans += cut_num
    if ans <= k:
        return True
    else:
        return False

left = 0.001
right = max_len
while right - left > 1:
    mid = (right + left) // 2
    if f(mid):
        right = mid
    else:
        left = mid
else:
    print(int(right))

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
import math
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]

def array2d(N, M, initial=0):
    return [[initial]*M for _ in range(N)]

def copy2d(orig, N, M):
    ret = array2d(N, M)
    for i in range(N):
        for j in range(M):
            ret[i][j] = orig[i][j]
    return ret


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


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

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

    
    left = 0
    right = 10**9+7
    
    while right - left > 1:
        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(right)

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)


def f(x, N, K, A):
    now = 0
    for i in range(N):
        now += (A[i]-1)//x
    return now <= K


def main(input, print):
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    l = 0
    r = 10**9
    while(r-l > 1):
        x = (l+r) // 2
        if f(x, N, K, A):
            r = x
        else:
            l = x
    print(r)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Solution (Python):
n, k = map(int, input().split())
A = [*map(int, input().split())]
A.sort(reverse=True)
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A:
        d = (a - 1) // m
        if d == 0: break
        c += d
    if c <= k: ok = m
    else: ng = m
print(ok)

Solution (Python):
n, k = map(int, input().split())
A = [*map(int, input().split())]
A.sort(reverse=True)
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A:
        d = (a - 1) // m
        if d > 0: c += d
        else: break
    if c <= k: ok = m
    else: ng = m
print(ok)

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

left = 0
right = max(A)


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

while (right-left)>1:
  mid = (left+right)//2
  if is_ok(mid):
    right = mid
  else:
    left = mid
    
print(right)

Solution (Python):
def check(x,k,arr):
    now = 0
    for i in range(len(arr)):
        now+=int((arr[i]-1)/x)
    return now<=k

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

r, l = 1e9, 0
while (l+1<r):
    x = int((r+l)/2)
    if check(x,k,arr):
        r = x
    else:
        l = x
print(int(r))

Solution (Python):
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30 
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a-1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Solution (Python):
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<32 
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a-1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Solution (Python):
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, max(A) 
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a-1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Solution (Python):
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 10**9 
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a - 1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Solution (Python):
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
ok = 10**9
ng = 0
while abs(ng-ok) > 1:
    mid = (ok + ng) // 2
    cnt = 0
    for i in a:
        cnt += (i+mid-1)//mid-1
    if cnt <= k:
        ok = mid
    else:
        ng = mid
print(ok)

Solution (Python):
import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += (math.ceil(A[i] / mid) - 1)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

if K == 0:  print(max(A))
else:
    left = max(A)
    right = 0
    ret = binary_search(right, left)
    print(ret)

Solution (Python):
import numpy as np
def solve(n, k, a):
    lb = 0
    ub = np.max(a)
    while ub - lb > 1:
        cur = (lb + ub) // 2
        cnt = np.sum(np.ceil(a/cur)) - n
        if cnt > k:
            lb = cur
        else:
            ub = cur
    return int(np.ceil((lb+ub) / 2))

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

Solution (Python):
import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
a=max(A)
l=1
y=copy.copy(a)
a=a-1
while l<=a:
    x=(l+a)//2
    m=0
    for i in range(N):
        if A[i]%x==0:
            m+=A[i]//x-1
        else:
            m+=A[i]//x
    if m<=K:
        a=x-1
        y=copy.copy(x)
    else:
        l=x+1
print(y)

Solution (Python):
N, K = map(int, input().split()[:2])
arr = list(map(int, input().split()[:N]))


def pos(X):
    sum = 0
    for i in arr:
        sum += int(i/X)
        if i % X == 0:
            sum -= 1
    return sum <= K


low = 1
high = 10 ** 9
mid = 0
ans = 10**9

while low <= high:
    mid = int((low+high)/2)
    
    if pos(mid):
        ans = mid
        high = mid-1
    else:
        low = mid+1
    
print(ans)

Solution (Python):
from math import ceil

N,K,*A = map(int, open(0).read().split())
left = 1
right = max(A)
while left != right:
    mid = (left+right) // 2
    temp = 0
    for x in A:
        temp += ceil(x/mid) - 1
        if temp > K:
            left = mid + 1
            break
    else:
        right = mid
for i in range(max(1,left-1),left+2):
    temp = 0
    for x in A:
        temp += ceil(x/i) - 1
        if temp > K:
            break
    else:
        print(i)
        break

Solution (Python):
from heapq import heappush, heappop, heapify
import math
def check(a,mid,k):
	cnt = 0
	for x in a:
		cur_cnt = (x+mid-1)//mid - 1
		cnt+=cur_cnt
		if cnt > k:
			return False
	return True

def solve():
	n , k= map(int, input().strip().split())
	a= [int(x) for x in input().strip().split()]
	l = 0
	r = 10**9+20
	while r-l > 1:
		mid = (r+l)//2
		if check(a,mid,k):
			r = mid
		else:
			l = mid
	return l+1
 
print(solve())

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

A = list(map(int, input().strip().split()))

minlen = 0
maxlen = 10**9

while maxlen-minlen > 1:
  mid = (maxlen + minlen)//2
  if mid == 0:
    cur = 1e9
  else:
  	cur = sum((a+mid-1)//mid - 1 for a in A)
  
  if cur > K:
    minlen = mid
  else:
    maxlen = mid

print(maxlen)

Solution (Python):
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:l,r,*_=(l,x:=l+r>>1,r)[-sum(-b//x+1for b in a)>k:]
print(r)

Solution (Python):
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:x=l+r>>1;l,r,*_=(l,x,r)[-sum(-b//x+1for b in a)>k:]
print(r)

Solution (Python):
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:x=l+r>>1;l,r,*_=(l,x,r)[-sum(-b//x+1for b in a)>k::]
print(r)

Solution (Python):


n,k=map(int,input().split())
a=[int(i) for i in input().split()]
    
ok=1001001001
ng=0
def check(x):
  cnt=0
  for q in a:
    cnt+=(q-1)//x
  return cnt<=k

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

Solution (Python):


n,k=map(int,input().split())
a=[int(i) for i in input().split()]
    
ok=1001001001
ng=0
def check(x):
  cnt=0
  for q in a:
    cnt+=(q-1)//x
  return cnt<=k

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

Solution (Python):
N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = 0
flag = True
mid = (left+right)//2
minN = right
result = mid
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
        if minN>mid:
            minN = mid
            result = mid
    elif count > K:
        left = mid
print(result)

Solution (Python):
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = a[-1] + 1

while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    for i in a:
        cnt += (i - 1) // mid
    if cnt <= K:
        r = mid
    else:
        l = mid
print(r)

Solution (Python):
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = a[-1] + 1

while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    for i in a:
        cnt += (i - 1) // mid
    if cnt <= K:
        r = mid
    else:
        l = mid
print(r)

Solution (Python):
temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
temparr = input()
import math
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
arr = sorted(arr)


left = 1
right = arr[-1] + 1
ans = arr[-1]
while left <= right:
    mid = (left + right) // 2 
    count = 0 
    for i in arr :
        if i <= mid:
            continue 
        else:
            count += math.ceil(i / mid) - 1 
    if count <= k :
        right = mid - 1 
        if mid < ans:
            ans = mid 
    else:
        left = mid + 1 
print(ans)

Solution (Python):

from math import ceil
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

if k==0:
    ans=max(a)
    print(ans)
    exit()
if k==1:
    if n==1:
        print(-(-a[0]//2))
        exit()
    ans=max(a[-1]/2,a[-2])
    print(ceil(ans))
    exit()
    
ok=10**9+1
ng=1
def check(x):
    k_cnt=0
    for q in a:
        k_cnt+=ceil(q/x-1)
    if k_cnt<=k:
        return True
    else:
        return False

    
for i in range(100):
    mid=(ok+ng)/2
    if check(mid):
        ok=mid
    else:
        ng=mid
    
print(ceil(ok))

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)


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

def check(x):
    sum_cut = 0
    for i in range(N):
        sum_cut += math.ceil(a[i]/x) - 1
    if sum_cut <= K:
        return True
    else:
        return False

M = 10**9 + 1
m = 1

x = (m+M) // 2

while True:
    y = x
    if check(x):
        M = x
        x = (m + x) // 2
    else:
        m = x
        x = (x + M) // 2

    if x == y:
        if check(x):
            print(x)
            sys.exit()
        else:
            print(x+1)
            sys.exit()

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

def f(x):
    count = 0
    for ai in a:
        count += (ai // x) - (ai % x == 0)
    return count <= k

left, right = 0, 10 ** 9
while right - left > 1:
    x = (left + right) // 2
    if f(x):
        right = x
    else:
        left = x

print(right)

Solution (Python):
N, K = map(int, input().split())
arr = list(map(int, input().split()))
def f(x):
    res = 0
    for i in range(N):
        if arr[i] % x != 0:
            res += arr[i]//x
        else:
            res += max((arr[i]//x)-1,0)
    return res
left = 0
right = max(arr)
while abs(left-right) > 1:
    tmp = (left+right)//2
    if f(tmp) > K:
        left = tmp
    else:
        right = tmp
print(right)

Solution (Python):
from heapq import heapify


def resolve():
    '''
    code here
    '''
    import math
    N, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

    def f(x):
        res = 0
        for item in As:
            res += (item-1)//x

        return res

    ng = 0
    ok = max(As)

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

        if f(mid) > K:
            ng = mid
        else:
            ok = mid
            
    print(ok)

if __name__ == "__main__":
    resolve()

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
def ok(l):
    cnt = 0
    for L in a:
        cnt += L//l
        if L%l != 0:
            cnt +=1
        cnt-=1
    return cnt<=k

bot,top=0,max(a)
while top - bot >1:
    mid = (top + bot) //2
    if ok(mid): top = mid
    else: bot = mid
print(top)

Solution (Python):

import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline



def valid(arr,l,cuts):
	
	
	for i in arr:
		cuts-=math.ceil((i)/l)-1;
	
	return cuts>=0;

n , k = map(int , input().split())
arr = list(map(int , input().split()))
arr.sort()
lo = 1
hi = max(arr)
while lo != hi:
	mid = (hi + lo)//2
	
	if valid(arr , mid,k):
		
		
		hi = mid
	else:
		lo = mid + 1
print(lo)

Solution (Python):

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

ng = 0
ok = max(A)

while abs(ok - ng) > 1:
  mid = (ok + ng) // 2
  cnt = 0
  for a in A:
    cnt += (a - 1) // mid
  if cnt <= k:
    ok = mid
  else:
    ng = mid

print(ok)

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


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


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

print(ok)

Solution (Python):
from math import ceil
N,K = map(int,input().split())
A = list(map(int,input().split()))
lb = 0
ub = max(A)
while True:
    X = (ub+lb)/2
    count = 0
    for i in range(N):
        count += ceil(A[i]/X-1)
    if count > K:
        lb = X
    else:
        ub = X
    if ceil(ub) == ceil(lb):
        print(ceil(ub))
        exit()

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

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

ng, ok = 0, 10 ** 10
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()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=1
high=max(A)
sig=(low+high)//2
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

Solution (Python):
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

Solution (Python):
from math import ceil

def check(A, K, L):
    i = 0
    for a in A:
        i += ceil(a/L)-1
        if i > K:
            return False
    return True

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
l = 0
r = A[0]
while l + 1 < r:
    m = (l+r)//2
    if check(A, K, m):
        r = m
    else:
        l = m
print(r)

Solution (Python):
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=1
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

Solution (Python):
def is_ok(mid):
    cnt = 0
    for i in range(n):
        cnt += (a[i] - 1) // mid
    return cnt <= k

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

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

Solution (Python):
def isok(mid):
    cnt = 0
    for i in range(N):
        if A[i] % mid == 0:
            cnt += A[i]/mid-1
        else:
            cnt += A[i]//mid
    if cnt <= K:
        return True
    else:
        return False

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


left = 0
right = 10**9

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

Solution (Python):
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

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

def check(x):
  count = 0
  for Ai in A:
    count += (Ai - 1)//x
  
  return count <= K


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

print(ok)

Solution (Python):
import sys

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

def main():
    N,K = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    left = 0
    right = A[-1]

    while right - left > 1:
        cnt = 0
        middle = (left + right) // 2
        for i in A:
            cnt += (i - 1) // middle
        if cnt <= K:
            right = middle
        else:
            left = middle
    print(right)


if __name__ == "__main__":
    main()

Solution (Python):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

N,K = map(int,input().split())
A = list(map(int,input().split()))
if K == 0:
    print(max(A))
else:
    s = 0
    g = 10**9
    mae = -1
    now = 1
    while now != mae:
        mae = now
        c = 0
        if (s + g)%2 == 0:
            now = (s + g)//2
        else:
            now = (s + g)//2+1        
        for i in range(N):
            if A[i]%now == 0:
                c += (A[i]//now)-1
            else:
                c += A[i]//now
        if c > K:
            s = now
        else:
            g = now
        
    print(now)

Solution (Python):
import math
n,k = map(int,input().split())
l = list(map(int,input().split()))
def cnt_check(longest):
    if longest == 0:
        return False
    cnt = 0
    for log in l:
        cnt += math.ceil(log/longest)-1
    if cnt <= k:
        return True
    else:
        return False
left = 0
right = max(l)
while right - left > 1:
    middle = (left + right)//2
    if cnt_check(middle):
        right = middle
    else:
        left = middle
print(right)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=0
r=a[-1]
while r-l>1:
  cnt=0
  m=(l+r)//2
  
  for i in a:
    cnt+=(i-1)//m
  if cnt<=k:
    r=m
  else:
    l=m
print(r)

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

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

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

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

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

    print(ans)
    return

def examF():
    
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            
            
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i + 1

        def debug(self, k):
            return [self.sum(i) for i in range(k)]

        def inversion(self, A=[3, 10, 1, 8, 5]):
            res = 0
            for i, p in enumerate(A):
                self.add(p, 1)
                res += i + 1 - self.sum(p)
            return res
    N, Q = LI()
    C = LI()
    LR = []
    lastAppeared = [-1]*N
    for i in range(Q):
        l, r = LI()
        LR.append((l,r,i))
    LR.sort(key=lambda x:x[1])
    
    bit = Bit(N+1)
    ans = [0]*Q
    r = 0
    now = 0
    while(r<N):
        if now==Q:
            break
        l0, r0, i0 = LR[now]
        while(r<r0):
            c = C[r]-1
            if lastAppeared[c]>0:
                bit.add(lastAppeared[c],-1)
            lastAppeared[c] = r+1
            bit.add(lastAppeared[c]+1)
            r += 1
        

        while(now<Q):
            l0,r0,i0 = LR[now]
            if r<r0:
                break
            
            ans[i0] = bit.sum(r0)
            if l0>1:
                ans[i0] -= bit.sum(l0-1)
            now += 1


    for v in ans:
        print(v)
    return

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

getcontext().prec = 9

sys.setrecursionlimit(10**5)

if __name__ == '__main__':
    examE()

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

Solution (Python):
from sys import stdin

def main():
    n, k = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    
    def ok(ans):
        cnt = sum(max((i - 1) // ans, 0) for i in a)
        
        return cnt <= k
    
    ans = 0
    for i in range(32, -1, -1):
        if not ok(ans + (1 << i)):
            ans += 1 << i
    print(ans + 1)

main()

Solution (Python):
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))

Solution (Python):






def isDividable(l,k,a):
  cnt = 0
  for Log in a:
    cnt += (Log - 1) // l
  return cnt <= k



def binary_search(ng,ok,k,a):
  while abs(ng-ok) > 1:
    mid = (ng + ok) // 2
    if isDividable(mid,k,a):
      ok = mid
    else:
      ng = mid
  return ok



def solve(k,a):
  return binary_search(0,max(a),k,a)



def main():
  N,K = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(K,a))
  return

if __name__ == '__main__':
  main()

Solution (Python):
from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())

n,k=ma()
a=lis()
l,h=0,max(a)
while(l+1<h):
    m=(l+h)//2
    c=0
    for i in a:
        c+=ceil(i/m)-1
    if(c<=k):
        h=m
    else:
        l=m
print(h)

Solution (Python):
from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())

n,k=ma()
a=lis()
l,h=0,max(a)
while(l+1<h):
    m=(l+h)//2
    c=0
    for i in a:
        c+=ceil(i/m)-1
    if(c<=k):
        h=m
    else:
        l=m
print(h)

Solution (Python):
import math

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

left=0
right=max(a)
mid = (left+right)/2
while right - left > 0.5:
    times = 0
    for i in range(n):
        times+=math.ceil(a[i]/mid)-1
    if times<=k:
        right=mid
        mid=(left+right)/2
    else:
        left = mid
        mid =(left+right)/2

print(math.ceil(mid))

Solution (Python):
import math
N,K = map(int,input().split())
cs = list(map(int, input().split()))
high = max(cs) + 1  
low = 0  
 
while high - low > 1:
  x = (high - low) // 2 + low
  cnt = 0
  for a in cs:
    cnt += math.ceil(a/x) - 1
 
  if cnt <= K:  
    high = x
  else:
    low = x
print(high)