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
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2






def solve():
    N, K = MI()
    A = LI()
    A.sort()
    

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

        if cnt > 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

    l = 0
    r = max(A)+1
    print(meguru_bisect(l, r))

if __name__ == '__main__':
    solve()

Solution (Python):
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
mi = 0
ma = max(a)
m = ma//2
while ma-mi>1:
  temp = 0
  for i in range(n):
    temp += ceil(a[i]/m)-1 
    
    
  if temp<=k:
    ma=m
    m=(ma+mi)//2
  else:
    mi = m
    m=(ma+mi)//2
  
  

print(m+1)

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
    
    now=0
    for i in A:
        now+= i//mid-1 if i%mid==0 else i//mid
    if now> k :
        ng=mid
    else:
        ok=mid

print(ok)

Solution (Python):
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]

def check(mid,k,ar):
    ct=k
    for i in ar:
        if(i<=mid):
            continue
        ct-=(i//mid)
    return ct>=0
def main():
    n,k=map(int,input().split())
    ar=inpt()
    i,j=1,100000000000
    while(i<j):
        mid=(i+j)//2
        if(check(mid,k,ar)):
            j=mid
        else:
            i=mid+1
    print(i)

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

if __name__ == "__main__":
    main()

Solution (Python):


import os
import sys
import numpy as np

def ncut(l, x):
  return np.sum(np.ceil(l / x) - 1)

def solve(N, K, AS):
  ng, ok = -1, np.amax(AS)
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if ncut(AS, mid) <= K:
      ok = mid
    else:
      ng = mid

  return ok.item()


def main():
  d = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
  N, K = d[:2]
  AS = d[2:]

  print('{}'.format(solve(N, K, AS)))

if __name__ == '__main__':
  main()

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

l = 0
r = 10**9


def check(v):
    c = k
    for i in logs:
        if i%v==0:
            p=i/v
        else:
            p=i/v+1
        if(p-1 <= c):
            c -= p-1
        else:
            return 0
    return 1


ans = 10**9
while l+1<r:
    mid = (l+r)/2
    if(check(mid)):
        ans = min(ans, mid)
        r = mid
    else:
        l = mid
print ans

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

l = 0
r = max(a)

while r - l > 1:
    cnt = 0
    mid = (r + l) // 2
    for i in range(n):
        d = (a[i] // mid) + (a[i] % mid != 0) - 1
        cnt += d
    if cnt <= k: r = mid
    else: l = mid 

print(r)

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

l = 0
r = max(a)

while r - l > 1:
    cnt = 0
    mid = (r + l) // 2
    for i in range(n):
        d = (a[i] - 1) // mid
        if d > 0: cnt += d
    if cnt <= k: r = mid
    else: l = mid 

print(r)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=0;R=10**9
while(R-L>1):
	M=L+R>>1;C=0
	for i in A:C+=(i-1)//M
	if C<=K:R=M
	else:L=M
print(R)

Solution (Python):
from math import ceil

def is_ok(arg):
    
    ret = 0
    for i in range(n):
        ret += ceil(A[i]/arg)-1
    return bool(ret<=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

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

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

Solution (Python):
import heapq
n , k = map(int,input().split())
a = list(map(int,input().split()))
lef = 0
rig = max(a)
while rig - lef != 1:
    now = -(-(lef+rig)//2)
    cou = 0
    for i in range(n):
        cou += -(-a[i]//now) - 1
    if cou <= k:
        rig = now
    elif cou > k:
        lef = now
print(rig)

Solution (Python):
from math import ceil

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


def is_ok(num):
  t = 0
  for log in logs:
    if log <= num:
      continue
    t += ceil(log / num) - 1
  return t <= k

ng = 0
ok = 10 ** 9

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

print(ceil(ok))

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

a.sort(reverse=True)
idx = 0
result = 0

bottom, top = 0, max(a)

while top - bottom > 1:
    mid = (top + bottom) // 2
    cnt = 0
    for i in range(n):
        cnt += a[i] // mid
        if a[i] % mid == 0:
            cnt -= 1
    if cnt <= k:
        top = mid
    else:
        bottom = mid

print(top)

Solution (Python):

def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]//x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

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

    if right == 1:
        return 1

    mid = 0
    while True:
        if right == 1:
            return 1
            
        mid = int( (left + right)/2 )
        
        judge = can_or_cannot(A,K,mid)
        
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            
            return right

print(main())

Solution (Python):



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

def cnt(x):
  ret = 0
  for ai in a:
    ret += (ai+(x-1))//x - 1
  return ret

ok, ng = a[-1], 0
while ok - ng > 1:
  nw = (ok + ng) // 2
  if cnt(nw)<=k:
    ok = nw
  else:
    ng = nw

print(ok)

Solution (Python):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
x0=0
x1=10**9
while(1):
    sum=0
    mid=(x0+x1)//2
    for i in range(n):
        sum+=math.ceil(a[i]/mid)-1
    if(sum<=k):
        x1=mid
    if(sum>k):
        x0=mid
    if(x0+1==x1):
        print(x1)
        break

Solution (Python):













from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy



MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): 
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): 
    return reduce(math.gcd, numbers)

def combination(m,n): 
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): 
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def f(n,a,c,K):
    now = 0
    for i in range(n):
        now += math.ceil(a[i]/c)-1
    return now <= K

def main():
    N,K = [int(x) for x in stdin.readline().rstrip().split()]
    A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    l,r = 0,int(1e9)
    while r-l > 1:
        c = (l+r)//2
        
        if f(N,A,c,K):
            r = c
        else:
            l = c
            
    print(r)
main()

Solution (Python):
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
low, high = 0, max(arr) + 1
while high - low > 1:
  mid = (high + low) // 2
  curr = 0
  for i in arr:
    curr += (i - 1)//mid
  if curr > k:
    low = mid
  else:
    high =  mid
print(high)

Solution (Python):

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

l=0
r=10**9

def check(x):
    now = 0
    for i in range(n):
        now += (a[i] - 1 )// x
    return now <= k

while r-l > 1:
    x = (l+r) //2
    if check(x):
        r = x
    else:
        l = x

print(r)

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

def is_ok(arg):
  cnt=0
  for i in a:
    cnt+=(i-1)//arg
  return k>=cnt
  
def binsearch(ng,ok):
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if is_ok(mid):
      ok=mid
    else:
      ng=mid
      
  return ok

print(binsearch(0,10**9+1))

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

def f(n):
    cnt = 0
    for a in a_i:
        cnt += (a - 1) // n
    if cnt > k: return False
    else: return True

l, r = 0, max(a_i)
while True:
    if r - l <= 1: break
    val = (l + r) // 2
    if f(val) == True: r = val
    else: l = val
print(r)

Solution (Python):
import math as m

def isltK(K,X):
    ccut=0
    for Ai in As:
        ccut += m.ceil(Ai/X)-1
    if ccut <=K:
        return True
    else:
        return False


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

l=1
h=max(As)
while l < h:
    mid = (l+h)//2
    if isltK(K,mid):
        h=mid
    else:
        l=mid+1
print(l)

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

l, r = 1, 10 ** 9
while l < r:
    m = (l + r) // 2
    if sum(map(lambda v: (v - 1) // m, a)) > k:
        l = m + 1
    else:
        r = m
print(l)

Solution (Python):

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




def f(n):
  cnt=0
  for aa in a:
    cuta=(aa-1)//n 
    cnt+=cuta
  if cnt>k:
    return False
  return True


l,r=0,max(a)
while r-l>1:
  m=(r+l)//2
  if f(m):
    r=m
  else:
    l=m


print(r)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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


def ok(X):
    cnt = 0
    for a in A:
        cnt += (a - 1) // X

    return cnt <= K


def solve():
    l, r = 0, 1000000000

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

    return r


print(solve())

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

def ok(s):
    c=0
    for i in a:
        c+=-(-i//s)-1
    return c<=k


l=0
r=max(a)
while r>l+1:
    md=(r+l)//2
    if ok(md):
        r=md
    else:
        l=md
print(r)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

def ok(s):
    c=0
    for i in a:
        c+=-(-i//s)-1
    return c<=k


l=0
r=max(a)
while r>l+1:
    md=(r+l)//2
    if ok(md):
        r=md
    else:
        l=md
print(r)

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

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











ok = max(A)
ng = 0

def isOk(x):
  cut = 0
  for a in A:
    cut += ((a + x - 1) // x) - 1
  return cut <= K
  
while abs(ok - ng) > 1:
  mid = abs(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()))

l = 1
r = max(A)
while l != r:
    mid = (r + l) // 2
    count = 0
    for log in A:
        count += (log - 1) // mid
    if count <= K:
        r = mid
    else:
        l = mid + 1

print(r)

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

l = 1
r = max(A)
while l != r:
    mid = (r + l) // 2
    count = 0
    for log in A:
        count += (log - 1) // mid
    if count <= K:
        r = mid
    else:
        l = mid + 1

print(r)

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

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

    for a in list_A:
        cnt += (a-1)//m

    if cnt > k:
        l = m
    else:
        r = m

print(r)

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

l = 0
r = max(A)
for _ in range(30):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)

Solution (Python):
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


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

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    

print(d_max)

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

l = 0
r = max(A)
for _ in range(100):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)

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

def can_cut(n):
    tmp = 0
    for a in A:
        tmp += ((a + n - 1) // n) - 1
    if tmp <= K:
        return True
    else:
        return False

l = 0
r = max(A) + 1
while l+1 < r:
    m = (l + r) // 2
    if can_cut(m):
        r = m
    else:
        l = m
print(r)

Solution (Python):
import numpy as np
import math

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

def isOK(minVal):
	tmpK=0
	for a in A:
		
		tmpK+=((-(-a//minVal))-1)

	if tmpK <= K:
		return True
	else:
		return False

ok = max(A)
ng = 0

while (math.ceil(ok) != math.ceil(ng)):
	mid = (ok+ng) / 2
	if isOK(mid):
		ok = mid
	else:
		ng = mid
	

print(math.ceil(ok))

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
tmax=max(a)
tmin=0
import math
ans=tmax
if k==0:
  print(tmax)
else:
  while True:
    t=(tmax+tmin)//2
    if abs(tmax-tmin)<=1:
      break
    s=0
    for i in range(n):
      s=s+math.ceil(a[i]/t)-1
    if k>=s:
      ans=min(math.ceil(t),ans)
      tmax=t
    else:
      tmin=t
  print(ans)

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

b = 0
e = max(A)
L = e // 2
while e - b > 1:
    L = (e + b) // 2
    m = sum(list(map(lambda x: (x - 1) // L, A)))
    if m <= k:
        e = L
    else:
        b = L
print(e)

Solution (Python):
from math import ceil
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = max(a)
def f(ln, x):
    return ceil(ln/x)-1
while r-l > 1:
    m = (r+l)//2
    cnt = 0
    for i in range(n):
        cnt += f(a[i],m)
    if cnt > k:
        l = m
    else:
        r = m
print(r)

Solution (Python):
import math
def judge(x):
    cnt=0
    for l in a:
        c=l//x
        if l%x!=0:
            c+=1
        cnt+=c-1 
    return cnt<=k

n,k=map(int,input().split())
a=list(map(int,input().split()))
left=0
right=max(a)
mid=(left+right)//2
while right-left>1:
    if judge(mid):
        right=mid
        mid=(left+right)//2
    else:
        left=mid
        mid=(left+right)//2
print(right)

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

def is_ok(X):
    
    cnt = 0
    for i in range(N):
        cnt += (A[i]-1)//X
    return cnt <= K
 
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**9))

Solution (Python):
"""
AtCoder :: Beginner Contest 174 :: Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
"""
import sys
from math import ceil


def main():
    """Main program."""
    log_count, cut_count = (int(i) for i in sys.stdin.readline().split())
    logs = [int(i) for i in sys.stdin.readline().split()]
    high = max(logs)
    low = 1
    soln = high
    
    while low <= high:
        mid = (low + high) // 2
        cuts_needed = sum([int(ceil(log / mid)) - 1 for log in logs])
        if cuts_needed <= cut_count:
            soln = min(soln, mid)
            high = mid - 1
        else:
            low = mid + 1
    print(soln)


if __name__ == '__main__':
    main()

Solution (Python):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=0,10**9
f=0
while r-l>1:
    m=(l+r)//2
    count=0
    for i in a:
        count+=math.ceil(i/m)-1
    if count<=k:
        r=m
    else:
        l=m
print(r)

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

s,l=0,max(A)
while l-s>1:
  m=(s+l)//2
  if sum([(a-1)//m for a in A]) >k:
    s=m
  else:
    l=m

print(l)

Solution (Python):
import math
def check(l, x, k):
  c = 0
  for a in l:
    c += math.ceil(a/x)-1
  if c <= k:
    return True
  else:
    return False

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

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

print(ok)

Solution (Python):
def resolve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    import math
    def isok(n):
        ndiv = 0
        for a in A:
            if a <= n:
                continue
            ndiv += math.ceil(a/n)-1
        return True if ndiv <= K else False 
    left = 0
    right = 10**9+1
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if isok(mid):
            right = mid
        else:
            left = mid
    print(math.ceil(right))


if '__main__' == __name__:
    resolve()

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

def ok(arg):
  cnt = 0
  for log in a:
    cnt += -(-log//arg)
    cnt -= 1
  return cnt<=k

st,en = 0,max(a)
mid = 0
while en-st>1:
  mid = (en+st)//2
  if ok(mid):
    en = mid
  else:
    st = mid

print(en)

Solution (Python):
import sys

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

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

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1


if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

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

left = 1
right= max(A)

import math

while True:
  
  cl = 0
  for i in range(N):
    cl += math.ceil(A[i]/left) - 1
  
  mid = (left + right)//2
  cm = 0
  for i in range(N):
    cm += math.ceil(A[i]/mid) - 1
  if(cl<=K):
    right = left
    break
  if(cm<=K):
    right = mid
  else:
    left = mid
  if(abs(left-right)<=1):
    break

print(right)

Solution (Python):
import math
n, k = map(int, input().split())
aas = list(map(int, input().split()))
diff = pow(10,-6)
left = 1
right = 10**9
def judge(mid):
    cut = 0
    for i in aas:
        cut += math.ceil(i / mid) - 1
    if cut <= k:
        return True
    else:
        return False
while left < right:
    mid = (left + right) / 2
    if (left <= right <= left + diff) or (right <= left <= right + diff):
        break
    elif judge(mid):
        right = mid
    else:
        left = mid
print(math.ceil(left))

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

left = 1
right= max(A)

import math

dict_X = {}
while True:
  
  cl = 0
  for i in range(N):
    cl += math.ceil(A[i]/left) - 1
  cr = 0
  for i in range(N):
    cr += math.ceil(A[i]/right) - 1
  
  mid = (left + right)//2
  cm = 0
  for i in range(N):
    cm += math.ceil(A[i]/mid) - 1
  if(cl<=K):
    right = left
    break
  elif(cm<=K):
    right = mid
  else:
    left = mid
  
  if(left>=right-1):
    break
    
print(right)

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

MIN=0
MAX=10**9
while MAX-MIN>1:
    mid=(MAX+MIN)//2
    tmp=0
    for i in range(N):
        tmp+=(A[i]-1)//mid
    if tmp>K:
        MIN=mid
    else:
        MAX=mid
print(MAX)

Solution (Python):
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
import math
def hoge(low, high, A, K):
    cnt = 0
    cut = (low + high) // 2
    for i in A:
        cnt += math.ceil(i / cut) - 1
        if cnt > K:
            return True
    return False
low = 1
high = max(A) + 1
cnt = 0
while True:
    if hoge(low,high,A,K):
        low = (low+high) // 2
    else:
        if high == (low + high) // 2 +1:
            if hoge(low,low,A,K):
                low += 1
        else:
            high = (low + high) // 2 +1
    if high - low == 1:
        break
    if cnt == max(A):
        break
    else:
        cnt += 1
print(low)

Solution (Python):
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
M = max(A)
m = 1
mid = (M+1)//2
while m<M:
  n = 0
  for a in A:
    n += -(-a//mid)-1
    if n > K:
      m = mid+1
      break
  else:
    M = mid
  mid = (M+m)//2
print(mid)

Solution (Python):
import math
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]


def binary_search(a, k):
    ng = 0 
    ok = max(a) 
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if sum([math.ceil(a[i]/mid)-1 for i in range(n)]) <= k:
            ok = mid
        else:
            ng = mid
    return ok
print(binary_search(a, k))

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

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

left = 0
right = 10**10

while right - left > 1:
    cut = 0
    mid = left + (right - left) // 2
    for a in A:
        cut += (a+mid-1)//mid - 1
    if cut <= K:
        right = mid
    else:
        left = mid

print(right)

Solution (Python):
import math

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

def binary_search(a, k):
    ng = 0 
    ok = max(a) 
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if sum([math.ceil(a[i]/mid)-1 for i in range(n)]) <= k:
            ok = mid
        else:
            ng = mid
    return ok

print(binary_search(a, k))

Solution (Python):
def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    '''
    ok = 10 ** 9  
    ng = 0        
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

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

        if cnt <= key:  
            ok = mid
        else:
            ng = mid
    
    return ok


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

print(binary_search(k))

Solution (Python):
def binary_search(key):
    '''
    条件を満たす最小のindexを求める
    '''
    right = 10 ** 9 + 1
    left = 0
    while right - left > 1:
        mid = (right + left) // 2

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

        if cnt <= key:
            right = mid
        else:
            left = mid
    
    return right


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

print(binary_search(k))

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
def test(d,m,u):
    global ans
    p = 0
    for i in range(n):
        if m < a[i]:
            p += a[i]//m
    if u-d <= 1:
        ans = max(ans,m)
        pass
    elif p > k:
        ans = max(ans,m)
        d = m
        m = -(-(m+u)//2)
        test(d,m,u)
    else:
        u = m
        m = -(-(m+d)//2)
        test(d,m,u)
d = 0
m = 1
u = 10**9+7
test(d,m,u)
print(ans)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while R-L > 0.001:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
if int(R) - int(L) == 0:
    print(int(R)+1)
else:
    print(int(R))

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

l = 0
r = 10**9 + 1
ref = 0

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

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

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

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

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

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

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

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

hi = 10 ** 9
lo = 0
while hi - lo > 1:
    mid = (hi + lo) // 2

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

    if cnt <= k:
        hi = mid
    else:
        lo = mid

print(hi)

Solution (Python):
import math
N,K = map(int, input().split())
A_list = list(map(int, input().split()))
lb = 0
ub = 10**9

for i in range(100):
    middle = (lb + ub)/2
    sumi = -N
    for a in A_list:
        sumi += math.ceil(a/middle)

    if sumi <= K:
        ub = middle
    else:
        lb = middle
print(math.ceil(middle))

Solution (Python):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]

l = 0
r = a[0] + 1
ref = 0
ans = a[0]

while r - l > 1:
    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)