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 sys
import math
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  


N, K = na()
A_array = na()

min_length = 0
max_length = 2 * 10 ** 9

while(max_length - min_length > 0.01):
    mid = (min_length + max_length) / 2
    cut_cnt = 0
    for a in A_array:
        c = a // mid
        if a - mid * c > 0:
            c += 1
        cut_cnt += (c - 1)
    
    if cut_cnt <= K:
        max_length = mid
    else:
        min_length = mid




ans1 = math.floor(max_length)
ans2 = math.ceil(max_length)

if ans1 == 0:
    print(1)
    exit()

cut_cnt = 0
for a in A_array:
    c = a // ans1
    if a - ans1 * c > 0:
        c += 1
    cut_cnt += (c - 1)

if cut_cnt <= K:
    print(ans1)
else:
    print(ans2)

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


ok, ng = 10 ** 9 + 1, 0
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    cnt = 0

    for a in A:
        if a <= x:
            continue

        cnt += a // x
        if cnt > K:
            ng = x
            break
    else:
        ok = x

print(ok)

Solution (Python):

N, K = map(int,input().split())
A = list(map(int,input().split()))
s = 0
t = max(A)

while s + 1 < t:
  m = (s + t) // 2
  temp = 0
  for i in A:
    temp += (i - 1) // m 
  if temp <= K: 
    t = m
  else: 
    s = m
print(t)

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

def foo(x):
    cnt = 0
    for i in range(n):
        cnt += (a[i]-1)//x
    return k>=cnt

n,k = inm()
a = inl()
mn = 0
mx = max(a)
while mn+1<mx:
    mid = (mn+mx)//2
    if foo(mid):
        mx = mid
    else:
        mn = mid
print(mx)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ok = max(a)
    ng = 0

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

    print(ok)


if __name__ == '__main__':
    main()

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

def cal( max_length ):
    cut_count = 0 
    for l in logs :
        cut_count += (l//max_length -1)
        if l % max_length != 0 :
            cut_count += 1
    return cut_count <= K 

i = 1 
j = max(logs)
while i < j :
    m = (i+j)//2
    if cal(m) :
        j = m
    else :
        i = m+1

print(i)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def cnt(m):
    res=0
    for a in aa:res+=(a+m-1)//m-1
    return res

n,k=MI()
aa=LI()
l=0
r=max(aa)
while l+1<r:
    m=(l+r)//2
    if cnt(m)>k:l=m
    else:r=m
print(r)

Solution (Python):

import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n,k = readints()
a = readints()

l = 0
r = 10**10

while r-l>1:
    m = (l+r)//2
    x = [(a[i]-1)//m for i in range(n)]
    if sum(x)<=k:
        r = m
    else:
        l = m

print(r)

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

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

fin = 1000000000000
def check(x):
	global arr, n, k, fin
	
	cur=0
	for i in range(n):
		cur+=(math.ceil(arr[i]/x)-1)
		
		if cur>k:
			return False
	
	return True

def bs(l, r):
	global arr, n, k, fin
	if r>=l:
		mid = l+(r-l)//2
		if check(mid):
			fin = min(fin, mid)
			bs(l, mid-1)
		else:
			bs(mid+1, r)

if k==0:
	print(max(arr))
else:
	bs(1, max(arr))
	print(fin)

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

def func(l,r):
    if l==r:
        return l
    mid = (l+r)//2
    count = 0
    for i in A:
        count += (i-0.1)//mid
    if count <= K:
        return func(l,mid)
    else:
        return func(mid+1,r)

print(func(1,max(A)))

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *A = map(int, read().split())

    ng = 0
    ok = 10 ** 9
    while ok - ng > 1:
        mid = (ok + ng) // 2
        res = 0
        for a in A:
            res += (a + mid - 1) // mid - 1
        if res <= K:
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()

Solution (Python):
n, k = map(int, input().split())
A = list(map(int, input().split()))
ng = -1
ok = max(A) + 1
def test(x):
    if x == 0:
      return False
    cnt = 0
    for a in A:
        if a > x:
            cnt += -(-a//x) - 1
    return cnt <= k

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

Solution (Python):
def check(N,target,A,K):
  cnt = 0
  for i in range(N):
    cnt += -(-A[i]//target)-1
  if cnt>K:
    return False
  return True

def solve():
  ans = 0
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  low = 0
  high = 10**9
  mid = (low+high)//2
  while high>low+1:
    if check(N,mid,A,K):
      high = mid
    else:
      low = mid
    mid = (low+high)//2
  ans = high
  return ans
print(solve())

Solution (Python):

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def pos(a, x, k):
    res = 0
    for i in a:
        res += (i-1)//x
    return res <= k

for _ in range(int(input()) if not True else 1):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    alpha = 1
    omega = 10**9
    while alpha < omega:
        mid = (alpha+omega) // 2
        if pos(a, mid, k):
            omega = mid
        else:
            alpha = mid+1
    print(omega)

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

L = 0
H = max(A)

def feasible(M): 
    S = sum([(a - 1) // M for a in A])
    
    return S <= K


assert(feasible(H))

while H - L > 1:
    
    M = (H + L) // 2
    if feasible(M):
        H = M
    else:
        L = M

print(H)

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

def is_ok(x):
    if x == 0:
        return False
    cnt = 0
    for a in A:
        q, r = divmod(a, x)
        if r == 0:
            cnt += q-1
        else:
            cnt += q
    if cnt <= k:
        return True
    else:
        return False

l = 0
r = 10**18
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        r = c
    else:
        l = c
print(r)

Solution (Python):
import sys

input = sys.stdin.buffer.readline
n, k = map(int, input().split())
A = list(map(int, input().split()))






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


ok = 10 ** 9
ng = 0

while ok - ng > 1:
    mid = (ok + ng) // 2
    if hantei(mid) <= k:
        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()))

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

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

ng = 0
ok = 10**9 + 1

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

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
def case(L):
    result=0
    for x in a:
        result+=(x-1)//L
    return result
possible=0
impossible=max(a)
while impossible-possible>1:
    M=(impossible+possible)//2
    if case(M)>k:
        possible=M
    else:
        impossible=M
print(impossible)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
n,k=map(int,input().split())
A=[int(i) for i in input().split()]

l,r=0,max(A)
cur=0
while cur<100:
	mid=(l+r)/2
	ct=0
	for a in A:
		if a<=mid:
			continue
		else:
			t=int(a/mid)
			if t*mid==a:
				t-=1
		ct+=t
	if ct<=k:
		r=mid
	else:
		l=mid
	cur+=1

ans=int(r)
if ans==r:
	print(ans)
else:
	print(ans+1)

Solution (Python):

import math

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

A.sort()
def isPossible(maxL):
    cuts = 0
    for x in A:
        if x > maxL:
            cuts += math.ceil(x / maxL) - 1
    return cuts <= K

lo = 0
hi = max(A)
EPS = 10e-7
while hi - lo > EPS:
    mid = (lo + hi) / 2
    if isPossible(mid):
        hi = mid
    else:
        lo = mid

print(math.ceil(hi))

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

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


def check(x):
    
    
    cnt = 0
    for ai in a:
        if ai > x:
            if ai % x == 0:
                cnt += ai // x - 1
            else:
                cnt += ai // x
    
    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):
from math import ceil
N,K = map(int,input().split())
A=list(map(int,input().split()))


low=0
high=10**9+1

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

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

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

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

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

N,K = map(int,input().split())
A = list(map(int,input().split()))
print(bisect(0,10**9))

Solution (Python):
n,k=[int(i) for i in raw_input().split()]
a=[int(i) for i in raw_input().split()]
s=0
for i in a:
    s+=i
val=(s+n+k-1)/(n+k)
for i in a:
    k-=i/val
if(k>=0):
    print val
else:
    k=abs(k)
    l=[]
    for i in a:
        x=i/val
        if(x>0):
            l.append((i+x-1)/x)
    l.sort()
    print l[k-1]

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

ng = 0
ok = 10**9

while ng < ok-1:
    mid = (ng+ok)//2
    
    count = sum((ai-1)//mid for ai in a)
    if count<=k: ok = mid
    else: ng = mid

print(ok)

Solution (Python):
from decimal import Decimal
from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
*A, = map(int, input().split())

tot = sum(A)

ng = 0
ok = 10**9

m = 4

while ng + 1 < ok:
    m = (ng+ok)//2
    c = sum((a-1)//m for a in A)
    if c > K:
        ng = m
    else:
        ok = m
print(ok)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,K = IL()
A = IL()

def count(x):
  ret = 0
  for a in A:
    ret += math.ceil(a/x)-1
  return ret

def is_ok(x):
  if count(x)>K:
    return False
  else:
    return True
  
def meguru_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(meguru_bisect(0,10**10))

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

    
    N, K = map(int, input().split())
    A = tuple(map(int, input().split())) 
    
    
    ma=max(A)
    l=0.0
    r=ma
    if K==0:
        print(ma)
        return

    def hantei(mid):
        cnt=0
        for a in A:
            cnt+=math.ceil(a/mid)-1
        return cnt<=K

    while r-l>1:
        mid=(l+r)//2
        if hantei(mid):
            r=mid
        else:
            l=mid
    mid=(l+r)//2



    print(int(r))

    



if __name__ == "__main__":
    main()

Solution (Python):

import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo


@mt
def slv(N, K, A):

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

    ans = Bisect(f).bisect_left(1, 1, 10**9+1)

    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil

def meguru_bisect(ng, ok):
    """
    初期値のng,okを受け取り, check=>Trueを満たす最大値(最小値)を返す
    条件を満たす最大値を求める場合、初期値は(ng:上限の外, ok:下限の外)   例) 10**9+1, -1
    条件を満たす最小値を求める場合、初期値は(ng:下限の外, ok:上限の外)   例) -1, 10**9+1
    上限の外や下限の外が返ってくる場合は条件を満たす値が範囲内になかったことを示すので、例外処理が必要
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok

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

n, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
ans = meguru_bisect(0, 10**9 + 1)
print(ans)

Solution (Python):
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
def c(x):
    cnt=0
    for i in a:
        cnt += i // x
    return cnt<=k
l, r = 0, max(a)
for i in range(100):
    mid = (l + r) / 2
    if c(mid):
        r = mid
    else:
        l = mid
print(ceil(l))

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, K = NMI()
    A = NLI()
    ng = 0
    ok = 10**10

    for i in range(100):
        mid = (ok + ng) // 2
        if mid == 0:
            break
        tmp = 0
        for a in A:
            if a % mid == 0:
                tmp += a // mid - 1
            else:
                tmp += a // mid
        if tmp <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int, input().split())
*arr, = map(int, input().split())

lo = 1
hi = max(arr) + 1

def can(arr, rem_length, k):
    cnt = 0
    for v in arr:
        cnt += (v - 1) // rem_length
    if cnt <= k:
        return True
    return False


while lo < hi:
    mid = (lo + hi) // 2
    if can(arr, mid, k):
        hi = mid
    else:
        lo = mid + 1


print(lo)

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

minL = 1
maxL = max(A)

while True:
    if minL >= maxL:
        break
    midL = (minL + maxL) // 2
    cut = 0
    for elem in A:
        cut += elem // midL
        if elem % midL == 0:
            cut -= 1
    if cut <= K:
        maxL = midL
    else:
        minL = midL + 1
print(maxL)

Solution (Python):

import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = [int(item) for item in input().split()]
l = 0; r = 1000000001
while r - l > 1:
    mid = (l + r) // 2
    cnt = 0
    for item in a:
        cnt += (item - 1) // mid
    
    if cnt <= k:
        r = mid
    else:
        l = mid

print(l + 1)

Solution (Python):
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
n,k=NM()
hi=10**9
lo=1
l=L()
def f(mi):
    x=0
    for i in l:
        if i<=mi:
            continue
        x+=(i+mi-1)//mi-1
    if x<=k:
        return True
    return False
while hi>=lo:
    mi=(hi+lo)//2
    if f(mi):
        hi=mi-1
    else:
        lo=mi+1
print(lo)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

n, k = LI()
A = LI()
ok = max(A)
ng = 0
while ok - ng > 1:
    cnt = 0
    mid = (ok + ng) // 2
    for a in A:
        if a % mid == 0:
            cnt += a // mid - 1
        else:
            cnt += a // mid
        if cnt > k:
            ng = mid
            break
    else:
        ok = mid

print(ok)

Solution (Python):
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

def Binary_Search(N, K, A):
	
	left = 0
	right = 10 ** 9
	ans = INF
	
	while left <= right:
		mid = (left + right) // 2
		val = 0
		if mid == 0:
			return 1
		for i in range(N):
			val += int((A[i] - 1) // mid)
		if val <= K:
			ans = min(ans, mid)
			right = mid - 1
		else:
			left = mid + 1

	return ans


def main():
	N, K = getlist()
	A = getlist()
	ans = Binary_Search(N, K, A)
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):


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

def num_cut(L):
  result = 0
  for a in A:
    result += a//L
    if a%L == 0:
      result -= 1
  return result

m = 0
M = 10**9

while M-m>1:
  X = (m+M)//2
  if num_cut(X)>K:
    m = X
  else:
    M = X

print(M)

Solution (Python):


import sys
input=sys.stdin.readline

n,k=map(int,input().split())
arr=list(map(int,input().split()))
l=0
r=max(arr)+1
while r-l!=1:
    persuit=(r+l)//2
    cnt=0
    for val in arr:
        if val<=persuit:
            continue
        if val%persuit==0:
            cnt+=val//persuit-1
        else:
            cnt+=val//persuit
    if cnt<=k:
        r=persuit
    else:
        l=persuit
print(r)

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

l = 0
r = 10**9+3
m = (l+r)//2
while r-l > 1:
    ans = 0
    for i in range(n):
        ans += -((-A[i])//m) - 1
    if ans > k:
        l = m
    else:
        r = m
    m = (l+r)//2
print(m+1)

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

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

l = 1
r = max(alst)

while r != l:
    pos = (r + l) // 2
    cnt = 0
    for a in alst:
        cnt += (a - 1) // pos
    if cnt <= k:
        r = pos
    else:
        l = pos + 1
print(r)

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



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

def determine(L):
    if L == 0:
        return False
    ret = 0
    for a in A:
        k = a // L
        if k * L == a:
            k -= 1
        ret += k

    if ret <= K:
        return True

    else:
        return False



L = 0
R = 10 ** 9

while L + 1 < R:
    mid = (L + R) // 2
    if determine(mid):
        R = mid
    else:
        L = mid

print(R)

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

ok, ng = 10**9+1, 0
while abs(ok-ng) > 1:
    mid = (ok+ng) // 2
    
    cnt = 0
    for a in al:
        a_cnt = (a-1)//mid
        cnt += max(0,a_cnt)

    if cnt <= k:
        ok = mid
    else:
    	ng = mid

print(ok)

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
now = 0
scale = 2**32
while scale:
  cnt = 0
  tmp = now + scale
  for x in a:
    cnt += (x-1) // tmp
  if cnt > k:
    now = tmp
  
  scale //= 2
print(now+1)

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

NG = 0
OK = 10**9 + 100

def Maruta(L):
    Kaisu = sum([a//L - 1 +  bool(a%L) for a in A])
    return Kaisu<=K

while OK - NG > 1:
    Test = (OK + NG)//2
    if Maruta(Test):
        OK = Test
    else:
        NG = Test
print(OK)

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



ok,ng=10**9+1,0
def enough(x):
    return sum( (i//x) for i in l if i>x)<=k

eps=10**(-3)
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if enough(mid):ok=mid
    else:ng=mid
print(ok)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = max(a)
while r - l > 1:
    
    c = (l + r) // 2
    t = 0
    for ai in a:
        t += (ai + c - 1) // c - 1
    if t <= k:
        r = c
    else:
        l = c
print(r)

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