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,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def Ra():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()




def dijkstra(edge,st):
    
    
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+c[cur]
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d

class UnionFind:
    def __init__(self, n):
        
        
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo



show_flg=False
show_flg=True

ans=0


n,k,*a=map(int,open(0).read().split())

def check(m):
    t=0
    for i in a:
        t+=max(int(i/m+1)-1,0)
    return t>k
        
l,r=0,10**9+10
c=0
while c<100:
    c+=1
    m=(r+l)/2
    l,r,*_=[l,m,r][check(m)::]

print(int(l+0.999999))

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

def lte_k(x, len_list):
    counter = 0
    for item in len_list:
        counter += math.ceil(item / x) - 1
    return counter <= k

def binary_search():
    low = 0
    high = max(a)

    while low < high-1:
        mid = (low + high) // 2
        guess = lte_k(mid, a)
        if guess:
            high = mid
        else:
            low = mid
    return high

print(binary_search())

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

a_max=max(a)

min1=0
max1=a_max

while max1-min1>1:
  zantei=(min1+max1)//2
  ans=0
  for x in range(n):
    if a[x]%zantei==0:
      ans+=a[x]//zantei-1
    else:
      ans+=a[x]//zantei
  if ans<=k:
    max1=zantei
  else:
    min1=zantei
    
print(max1)

Solution (Python):
from math import ceil



def main(N, K, A):
    
    def check(x):   
        cnt = 0 
        for a in A:
            cnt += ceil(a / x) - 1  
        return cnt <= K 

    l, r = 0, max(A)    
    while l < r - 1:    
        mid = (l + r) // 2
        if check(mid): 
            r = mid
        else:
            l = mid
    print(r)


if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    main(N, K, A)

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

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


def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


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


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

Solution (Python):
import math
def do():
    l = 0
    r = 10**9 + 1
    res = 10**10
    while l <= r:
        mid = (l+r) // 2
        if do2(mid) is True: 
            res = min(res, mid)
            r = mid - 1
        else:
            l = mid + 1
    return l


def do2(target):
    res = 0
    if target == 0:
        return False
    t = math.log(target, 2)
    kk = k
    for i in range(n):
        if target >= dat[i]:
            break
        kk -= math.ceil(dat[i] / target) - 1
        if kk < 0:
            return False
    return True

n, k = map(int, input().split())
dat = list(map(lambda x: int(x), input().split()))
dat.sort(reverse=True)
print(do())

Solution (Python):
import math
def do():
    l = 0
    r = 10**9 + 1
    res = 10**10
    while l <= r:
        mid = (l+r) // 2
        if do2(mid) is True: 
            res = min(res, mid)
            r = mid - 1
        else:
            l = mid + 1
    return res


def do2(target):
    res = 0
    if target == 0:
        return False
    t = math.log(target, 2)
    kk = k
    for i in range(n):
        if target >= dat[i]:
            break
        kk -= math.ceil(dat[i] / target) - 1
        if kk < 0:
            return False
    return True

n, k = map(int, input().split())
dat = list(map(lambda x: int(x), input().split()))
dat.sort(reverse=True)
print(do())

Solution (Python):





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

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

left=0
right=max(a)
while right-left>1:
  mid=(right+left)//2
  if check(mid):
    right=mid
  else:
    left=mid
print(right)

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

def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    
    l,r = 0, max(A)
    while l < r-1:
        mid = (l+r)//2
        cnt = 0
        for a in A:
            if a % mid:
                cnt+= a//mid
            else:
                cnt += a//mid - 1
            
        if cnt <= K:
            r = mid
        else:
            l = mid
    print(r)
    
main()

Solution (Python):

import math

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]








n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    for i in range(n):
        ans += math.ceil(li[i]/x) - 1
    if ans <= k:
        return True
    else:
        return False
left = 0
right = 10**9+1
while abs(left-right) > 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]








n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    if x == 0:
      return False
    else:
      for i in range(n):
        ans += math.ceil(li[i]/x) - 1
      if ans <= k:
          return True
      else:
          return False
left = 0
right = 10**9+1

while right != left + 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)

Solution (Python):
import sys
import math

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(ok, ng):
        """
        is_okを定義して下さい
        :param ok: 取りうる最小の値-1
        :param ng: 取りうる最大の値+1
        :return: is_okを満たす最小(もしくは最大)の値
        """
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

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

        return cnt <= k

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

    res = meguru_bisect(10 ** 9 + 1, 0)
    print(math.ceil(res))


if __name__ == '__main__':
    resolve()

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


memo={0:False}
def isOK(x):
  if x in memo:
    return memo[x]
  
  num_cut=0
  for a in alist:
    num_cut+=-(-(a-x)//x)
    if num_cut>K:
      memo[x]=False
      return False  
    
  memo[x]=True
  return True

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

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

top = max(a)
bottom = 0

while (top - bottom) > 1:
    mid = (top + bottom) // 2
    div_n = lambda a: (a + mid - 1) // mid - 1
    cnt = sum(map(div_n, a))
    if cnt <= k:
        top = mid
    else:
        bottom = mid

print(top)

Solution (Python):
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  lis.insert(now+1, item)
  return lis

C = sum(cut)
res = K - C
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(length, a)
  length.pop()

print(math.ceil(length.popleft()[0]))

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

Solution (Python):
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  lis.insert(now+1, item)
  return lis

C = sum(cut)
res = K - C
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(length, a)
  length.pop()

print(math.ceil(length.popleft()[0]))

Solution (Python):
import math
from collections import deque
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
S = np.sum(A)
cut = K*A//S

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  lis.insert(now+1, item)
  return lis

C = np.sum(cut)
res = K - C
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(length, a)
  length.pop()

print(math.ceil(length.popleft()[0]))

Solution (Python):
from math import ceil


def main():
    n, k = map(int, input().split())
    a = sorted([int(i) for i in input().split()], reverse=True)
    left = 0
    right = a[0]
    while right - left > 1:
        ki = k
        mid = left + (right - left) // 2
        for ai in a:
            if ki < 0:
                left = mid
                break
            if ai <= mid:
                right = mid
                break
            ki -= ceil(ai / mid) - 1
        else:
            if ki < 0:
                left = mid
            else:
                right = mid
    print(right)


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil

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

left = 0
right = max(a)

while right - left > 1:
    length = (right + left) // 2
    totcut = 0
    for i in range(n):
        totcut += ceil(a[i]/length) - 1
        if totcut > k:
            left = length
            break
    else:
        right = length
print(right)

Solution (Python):
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return deque(lis[:now+1] + [item] + lis[now+1:])

res = K - sum(cut)
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(list(length), list(a))
  length.pop()

print(math.ceil(length.popleft()[0]))

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

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

high=a[-1]
low=0
while (high-low)>1:
  mid =(high+low)//2
  if counter(mid):
    high=mid

  else:
    low=mid

print(high)

Solution (Python):
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return deque(lis[:now+1] + [item] + lis[now+1:])
  

C = sum(cut)
res = min(K - C, N)
length = length[:res+1]
length = deque(length)
for k in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    length.append(a)
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(list(length), list(a))
  length.pop()

print(math.ceil(length.popleft()[0]))

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):
from math import ceil
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
if K==0:print(max(A));exit()

left,right=0,10**9+1
while right>left+1:
    cnt=K
    mid=(left+right)//2
    for i in range(N):
        cnt -=ceil(A[i]/mid)-1
    if cnt>=0:right=mid
    elif cnt<0:left=mid

print(right)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N, K = MAP()
A = LIST()

def is_OK(X):
	cnt = 0
	for a in A:
		cnt += (a-0.1)//X
		if K < cnt:
			return False
	else:
		return True

l = 0
r = max(A)

while l != r-1:
	m = (r+l)//2
	if is_OK(m):
		r = m
	else:
		l = m

print(r)

Solution (Python):
import math

def resolve():
    _,K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    start = 0
    end = 10**9

    while end - start > 1:
        cnt = 0
        mid = (start + end) // 2
        for a in A:
            cnt += math.ceil(a/mid) - 1
        if cnt <= K:
            end = mid
        else:
            start = mid

    print(end)
    
resolve()

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

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

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

print(ok)

Solution (Python):
from bisect import bisect_left

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    def check(x):
        index = bisect_left(A,x)
        ans = 0
        for i in range(index,N):
            tmp = -(-A[i] // x) - 1
            ans += tmp
        if ans <= K:
            return True
        else:
            return False
    ok = max(A)
    ng = 0
    while abs(ok- ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == "__main__":
    main()

Solution (Python):
from bisect import bisect_left

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    def check(x):
        index = bisect_left(A,x)
        ans = 0
        for i in range(index,N):
            if A[i] % x == 0:
                tmp = (A[i] // x) - 1
            else:
                tmp = A[i] // x
            ans += tmp
        if ans <= K:
            return True
        else:
            return False
    ok = max(A)
    ng = 0
    while abs(ok- ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == "__main__":
    main()

Solution (Python):
import math

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

start = 0
end = max(a)
middle = (end+start) // 2

while end - start > 1:
    count = 0
    for i in range(n):
        if a[i] > middle:
            count += math.ceil(a[i] / middle) - 1
            
    if count <= k:
        end = middle
    else:
        start = middle
        
    middle = (end+start) // 2
    
print(end)

Solution (Python):
def is_ok(mid, array, k):
    if mid == 0:
        return False

    n = len(array)
    for i in range(n):
        if k - array[i] // mid >= 0:
            k -= array[i] // mid if array[i] % mid != 0 else array[i] // mid - 1
        else:
            return False

    return True


def bin_search(ng, ok, array, k):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid, array, k):
            ok = mid
        else:
            ng = mid
    return ok


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

max_len = max(a)

print(bin_search(0, max_len, a, k))

Solution (Python):
(N,K) = map(int,input().split())
l = input().split()
max = 0
for i in range(N):
    l[i]= int(l[i])
    if max <= l[i]:
        max = l[i]

lb = 0
ub = max

def cut(m):
    k = 0
    for i in range(N):
        k += -((-1*l[i])//m)-1
    return k

while ub - lb > 1:
    if cut((ub+lb)//2)>K:
        lb = (ub+lb)//2
    else:
        ub = (ub+lb)//2

print(ub)

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

max_length = max(arr)
low = 1
high = max_length - 1

while low <= high:
  mid = (low + high) //2
  cnt = 0
  for i in range(n):
    cnt += math.ceil(arr[i]/mid) - 1
  if cnt > k:
    low = mid + 1
  else:
    high = mid -1
    max_length = mid

print(max_length)

Solution (Python):
import math

n,k = map(int,input().split())
a = tuple(map(int,input().split()))
l = 0
r = max(a)
count = 0
while(count < 100):
  m = (l+r)/2
  kk = 0
  for ai in a:
    kk += math.ceil(ai/m-1)
  
  if kk <= k:
    r = m
  else:
    l = m
  count += 1
print(math.ceil(l))

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

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

a.sort()

max_tree = max(a)

min_tree = 0

while min_tree+1 != max_tree:
    mid_tree = (max_tree+min_tree)//2
    tmp_count = 0
    for i in range(n-1,-1,-1):
        if a[i] < mid_tree:
            break
        
        if a[i]%mid_tree == 0:
            tmp_count += a[i]//mid_tree-1
        else:
            tmp_count += a[i]//mid_tree

    if k < tmp_count:
        min_tree = mid_tree
    else:
        max_tree = mid_tree
    
print(max_tree)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    low, high = 0, max(A)
    while high - low > 1:
        mid = (high + low) // 2
        count = 0
        for a in A:
            if a % mid == 0:
                count += (a // mid - 1)
            else:
                count += (a // mid)
        if count <= K: high = mid
        else: low = mid
    print(high)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
ok = 10**10
ng = 0


def judge(x):
    cnt = 0
    for aa in a:
        cnt += (x + aa - 1) // x - 1
        
    return cnt <= k






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

Solution (Python):
from collections import deque


def can_cut(x):
    tmp = 0
    for a in A:
        tmp += (a-1)//x
        if tmp > K:
            return False

    return True


if __name__ == "__main__":
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    
    x_min = 0
    x_max = 10**9

    while x_max-x_min != 1:
        x = (x_max+x_min)//2
        if can_cut(x):
            x_max = x
        else:
            x_min = x

    print(x_max)

Solution (Python):
import sys,math,collections,itertools,heapq
input = sys.stdin.readline

N,K=list(map(int,input().split()))
A = list(map(int,input().split()))
under=0
upper=max(A)
num = upper//2

while True:
    ans = 0
    if num == 0:
        print(1)
        exit()
    for a in A:
        ans += math.ceil(a/num)-1
    if ans >K:
        under = num
        num = math.ceil((num+upper)/2)
    else:
        upper = num
        num = math.floor((num+under)/2)
    if upper-under ==1:
        print(upper)
        break

Solution (Python):

import sys
from math import ceil
def main(N, K, A):
    A.sort(reverse=True)

    def f(x):
        res = 0
        for a in A:
            if a > x:
                res += a // x
            else:
                break
        return res

    lo = 0
    hi = 10**9
    for _ in range(100):
        m = (lo + hi) / 2
        if f(m) > K: lo = m
        else: hi = m
    print(ceil(lo))

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    *A, = map(int, input().split())
    main(N, K, A)

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

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

    high = max(A)
    low = 0
    while high > low + 1:
        mid = (high+low) // 2
        cnt = 0
        for x in A:
            cnt += math.ceil(x/mid) - 1
        if cnt > K:
            low = mid
        else:
            high = mid
    print(high)



if __name__ == '__main__':
    main()

Solution (Python):








import io
import sys
import math


_DEB = 0   

_INPUT = """\
2 1
1 3
"""






_EXPECTED = """\
ABC
"""
if _DEB:
    sys.stdin = io.StringIO(_INPUT)
    print("!! Debug Mode !!")


def logd(str):
    if _DEB: print(f"[deb] {str}")


def f(m):
    cut=0
    for aa in a:
        
        c=(aa-1)//m 
        cut+=c
        if cut > k:
            return False
    return True




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


def solve():
    

    ans=0
    l,r=0,10**9
    while abs(r-l)!=1:
        m=(l+r)//2
        if f(m): 
            r=m
        else: 
            l=m
    
    ans=r
    

    
    ans = str(ans)
    print(ans)
    return ans


if __name__ == "__main__":
    ans = solve()

    
    if _DEB:
        if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!")
        else: print(f"\n!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Solution (Python):








import io
import sys
import math


_DEB = 0   

_INPUT = """\
2 1
1 50
"""






_EXPECTED = """\
ABC
"""
if _DEB:
    sys.stdin = io.StringIO(_INPUT)
    print("!! Debug Mode !!")


def logd(str):
    if _DEB: print(f"[deb] {str}")


def f(m):
    cut=0
    for aa in a:
        c=math.ceil(aa/m)
        cut+=c-1
        if cut > k:
            return False
    return True




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


def solve():
    

    ans=0
    l,r=0,10**9
    while abs(r-l)!=1:
        m=(l+r)//2
        if f(m): 
            r=m
        else: 
            l=m
    
    ans=r
    

    
    ans = str(ans)
    print(ans)
    return ans


if __name__ == "__main__":
    ans = solve()

    
    if _DEB:
        if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!")
        else: print(f"\n!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Solution (Python):
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)


l = 0
r = 2 * 10 ** 9 + 10 ** 6
while r - l > 1:
    m = (r + l) // 2
    cnt = ((A + m - 1) // m).sum()
    if cnt <= N + K:
        r = m
    else:
        l = m

print(r)