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


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


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


    ng =0
    ok =10**9+1

    while ok -ng >1:
        mid = (ok+ng)//2
        ans =0
        for i in range(N):
            ans += A[i]//mid -1
            if A[i]%mid !=0:
                ans +=1

        if ans <=K:
            ok =mid
        else:
            ng =mid

    print(ok)



if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int,input().split())
A = list(map(int,input().split()))
start = 0
end = 10**9
while end - start > 1:
   l = (start + end)/2
   l = int(l)
   count = 0
   for i in range(N):
      q = A[i]/l
      if q == int(q):
         q -= 1
      count += int(q)
   if count <= K:
      end = l
   else:
      start = l
print(end)

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


def cut(x):
    cut_count = 0
    for i in range(n):
        cut_count += (a[i]-1)//x
    return cut_count


l = 0
r = 10**9
while r-l > 1:
    mid = (l+r)//2
    if k >= cut(mid):
        r = mid
    else:
        l = mid
print(r)

Solution (Python):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
mini = 0
maxi = max(A)
while maxi - mini > 1:
    mid = (maxi+mini)//2
    s = sum(math.ceil(a/mid)-1 for a in A)
    if s>K:
      mini = mid
    else:
      maxi = mid
print(mini+1)

Solution (Python):
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,K=map(int,input().split())
A=list(map(int,input().split()))
ue=sum(A)
sita=1
for i in range(50):
  n=(ue+sita)//2
  L=[waru(i,n)-1 for i in A]
  if sum(L)>K:
    sita=n
  else:
    ue=n
  if ue==sita:
    print(ue)
    exit()
  elif ue-sita==1:
    n=sita
    L=[waru(i,n)-1 for i in A]
    if sum(L)>K:
      print(n+1)
      exit()
    else:
      print(n)
      exit()

Solution (Python):
import math

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


min_A = 0
max_A = 10**10

while( max_A - min_A > 1):
  now = (min_A + max_A) // 2
  temp = 0
  for i in A:
    if i > now:
      temp += (i // now)
  if temp > K:
    min_A = now
  else:
    max_A = now

print(int(min_A) + 1)

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

l = 0
r = 10**10

while r > l + 1:
    m = (r+l)//2
    count = 0
    for i in a:
        if i <= m:
            continue
        count += (i)//m
        
    if count > k:
        l = m
    else:
        r = m
    
print(r)

Solution (Python):
import math

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

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

def binary_search():
    left = 0
    right = max(A) + 1

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

    return right

print(binary_search())

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

Solution (Python):
n,k=map(int,input().split())
*a,=map(int,input().split())
l,r=0,10**9
while r-l>1:
    m=(l+r)//2
    t=0
    for x in a:
        if x<=m:
            continue
        t+=(x+m-1)//m-1
    if t<=k:
        r=m
    else:
        l=m
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:
    b = 0; x = (l+r)//2
    for i in range(n): b += (a[i]-1)//x
    if k < b:
        l = x
    else:
        r = x
print(r)

Solution (Python):
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
A = sorted(A, reverse=True)

l = 0
r = max(A)+1
def cut(l, k):
    
    for a in A:
        if a > l:
            k -= (-(-a//l) - 1)
    return k >= 0

while r-l > 1:
    mid = (r+l)//2
    if cut(mid, k):
        r = mid
    else:
        l = mid
print(r)

Solution (Python):
n,k,*a = map(int,open(0).read().split())
def func(b):
  c = k
  for i in a:
    c -= (i-1)//b
    if c < 0:
      return False
  return True
l = 1
r = max(a)
while(r>l):
  lr = (l+r)//2
  if func(lr):
    r = lr
  else:
    l = lr + 1
print(r)

Solution (Python):
import math

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

def cal(lis,x):
    an = 0
    for i in range(len(lis)):
        an += (math.ceil(lis[i] / x) - 1)
        
    return an

left = 0
right = 10**9

for i in range(100):
    m = (left + right) / 2
    
    b = cal(a,m)
    
    if b > k:
        left = m
    else:
        right = m
        
print(math.ceil(m))

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

def check(x):
  c = 0
  for i in range(n):
    c += a[i]//x
    if a[i]%x == 0:
      c -= 1
  if c <= k:
    return True
  else:
    return False

mx = max(a)
mn = 0
ans = [mx]
while mn <= mx:
  m = (mx+mn)//2
  if m == 0:
    if check(1):
      ans.append(1)
    break
  if check(m):
    mx = m - 1
    ans.append(m)
  else:
    mn = m + 1
print (min(ans))

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

left=1
right=10**9
while left<right:
  cnt=0
  mid=(left+right)//2
  for i in range(n):
    cnt+=math.ceil(a[i]/mid)-1
  if cnt<=k:
    right=mid
  else:
    left=mid+1
print(left)

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

low = 0
high = max(a)

while low + 1 < high:
    mid = (low + high) // 2
    m = 0
    for x in a:
        m += (x - 1) // mid
    
    if m <= k:
        high = mid
    else:
        low = mid

print(high)

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

def is_ok(mid):
    s = 0
    for j in range(N):
        if mid < A[j]:
            s += A[j] // mid
    return s <= K

max_A = 10**9 + 1
ng = 0
ok = max_A

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

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
    t=(l+r)//2
    if sum((i-1)//t for i in a)>k:
        r=t
    else:
        l=t
print(l)

Solution (Python):
import math

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

r = max(As)

if K == 0:
  print(r)
  exit()
  
l = 1

while l < r:
  mid = (r + l)//2
  cnt = 0
  for a in As:
    cnt += math.ceil(a/mid) - 1
  if cnt <= K:
    r = mid
  else:
    l = mid + 1
  
print(r)

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

def check(l):
    count = 0
    for L in A:
        count += L // l
        if L % l != 0:
            count += 1
        count -= 1
    return count <= K

bottom, top = 0, max(A)

while top - bottom > 1:
    mid = (top + bottom) // 2
    if check(mid):
        top = mid
    else:
        bottom = mid

print(top)

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

r = max(A)
l = 0

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

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

max_l = 10**9
min_l = 0
while max_l - min_l != 1:
    count = 0
    mean = (max_l+min_l)//2
    for i in range(n):
        count += -(-a[i]//mean)-1
    if count <= k:
        max_l = mean
    else:
        min_l = mean
print(max_l)

Solution (Python):
import math

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

l = 0
r = max(list)

while r - l > 1:
  count = 0
  x = (r + l)//2

  for i in range(len(list)):
    if x >= list[i]:
      continue
    count += math.ceil(list[i]/x) - 1

  if count <= k:
    r = x
  else:
    l = x

print(r)

Solution (Python):
def main():
    n, k = map(int, input().split())
    arr = list(map(int, input().split()))
    L, R = 0, max(arr)
    while L+1 < R:
        P = (L+R+1)//2
        cnt = 0
        for a in arr:
            if P < a:
                if a % P == 0:
                    cnt += a//P - 1
                else:
                    cnt += a//P
        if cnt <= k:
            R = P
        else:
            L = P
    print(R)

if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = 10**9
while (r-l>1):
    x = (r+l)//2
    now = 0
    for a in A:
        now += (a-1)//x
    if now <= K:
        r = x
    else:
        l = x
print(r)

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

bottom, top = 0, max(A)

def cut(x):
    cnt = 0
    for Length in A:
        if Length % x == 0:
            cnt += Length // x
        else:
            cnt += Length // x + 1
        cnt -= 1
    return cnt <= k

while top - bottom > 1:
    middle = (top + bottom) // 2
    if cut(middle):
        top = middle
    else:
        bottom = middle
    
print(top)

Solution (Python):
import math

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

def seikai(x):
    count = 0
    for i in range(n):
        count += math.ceil(a[i] / x) - 1

    if(count <= k):
        return 1
    else:
        return 0

l = 0
r = 10 ** 9
while(r - l > 1):
    temp = (r + l) // 2
    if(seikai(temp) == 1):
        r = temp
    else:
        l = temp

print(r)

Solution (Python):
import math

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

L = 1
R = 10**9+1
ans = float("INF")

while True: 
    mid = (L + R) // 2
    cur = 0
    for i in range(N):
        cur += math.ceil(A[i]/mid) - 1 
    
    if cur > K: 
        if L == mid:
            break
        L = mid
    else: 
        ans = min(ans, mid)
        if R == mid:
            break
        R = mid
        
print(ans)

Solution (Python):
from math import ceil
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
def is_ok(x):
  c=0
  for i in a:
    c+=ceil(i/x)-1
    if c>k:
      return False
  return True
def binary_search(m): 
  left=0
  right=m+1
  while left<=right:
    center=(left+right)//2
    if right-left==1:
      return right
    elif is_ok(center):
      right=center
    else:
      left=center
if k==0:
  print(max(a))
else:
  print(binary_search(max(a)))

Solution (Python):






import math




def solve(N, K, As):
    ans = max(As)
    l, r = 1, ans
    for _ in range(30):
        m = (l + r) // 2
        cnt = 0
        for A in As:
            cnt += math.ceil(A / m) - 1
        if cnt <= K:
            ans = min(ans, m)
            r = m - 1
        else:
            l = m + 1
        if l > r:
            break
    print(ans)


if __name__ == '__main__':
    
    
    N, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    
    solve(N, K, As)

Solution (Python):






import math




def solve(N, K, As):
    ans = max(As)
    l, r = 1, ans
    for _ in range(30):
        m = (l + r) // 2
        if m <= 0:
            break
        cnt = 0
        for A in As:
            cnt += math.ceil(A / m) - 1
        if cnt <= K:
            ans = min(ans, m)
            r = m - 1
        else:
            l = m + 1
    print(ans)


if __name__ == '__main__':
    
    
    N, K = map(int, input().split())
    As = [int(i) for i in input().split()]
    
    solve(N, K, As)

Solution (Python):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, k = nm()
    a = nl()
    ng = 0
    ok = max(a) + 1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        cnt = 0
        for x in a:
            cnt += (x - 1)//mid
        if cnt > k:
            ng = mid
        else:
            ok = mid
    print(ok)
    return

solve()

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


def cut_num(a, cut_length):
    return math.ceil(a/cut_length) - 1


"""cut length N binary search
if cut num > K, search more longer cut length,
"""
l = 1
r = max(As)

while r > l + 1:
    m = (l+r)//2
    current_cut_num = sum([cut_num(a, m) for a in As])
    if current_cut_num <= K:
        r = m
    else:
        l = m
    

if sum([cut_num(a, l) for a in As]) <= K:
    print(l)
else:
    print(r)

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


def cut_num(a, cut_length):
    return math.ceil(a/cut_length) - 1


"""cut length N binary search
if cut num > K, search more longer cut length,
"""
l = 1
r = max(As)
m = (l+r)//2
ans = r
while r > l + 1:
    current_cut_num = sum([cut_num(a, m) for a in As])
    if current_cut_num <= K:
        r = m
    else:
        l = m
    m = (l+r)//2

if sum([cut_num(a, l) for a in As]) <= K:
    print(l)
else:
    print(r)

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

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

left=1
right=10**9+1
ans=float("INF")
while True:
    mid=(left+right)//2
    now=0
    for i in range(N):
        now+=ceil(A[i]/mid)-1

    if now>K:
        if left==mid:
            break
        left=mid
    else:
        ans=min(ans, mid)
        if right==mid:
            break
        right=mid

print(ans)

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

l = 0
r = max(A)
while l + 1 < r:
    m = (l+r)//2
    n = sum([(x-1)//m for x in A])
    if n > K:
        l = m
    else:
        r = m
print(r)

Solution (Python):

import math

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

A = [int(y) for y in input().split()]

Ma = max(A)
mi = 1

ans = Ma

def execute(f):
    count = 0
    for i in A:
        count += math.ceil(i / f) - 1
    if count <= K:
        return True
    else:
        return False

while True:
    median = (Ma + mi) // 2
    
    bobo = execute(median)
    
    if bobo:
        ans = min(ans,median)
        Ma = median
    else:
        mi = median + 1
    
    if Ma == mi:
        break

print("{}".format(ans))

Solution (Python):
import math

def count(N,K,mid,a):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(a[i]/mid-1)
    if cnt > K:
        return False
    else:
        return True

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

    low = 1
    high = 10**9+1
    mid = (low+high)//2

    while high > low+1:
        if count(N,K,mid,a):
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    if count(N,K,low,a):
        print(low)
    else:
        print(high)

main()

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

x0, x1 = 0, 10**9
while x0 + 1  < x1:
  x = (x0+x1)//2
  suma=0
  for i in a:
    if i%x==0:
      suma+=(i//x)-1
    else:
      suma += (i//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    count = 0
    for i in range(n):
        if a[i] % arg != 0:
            count += a[i] // arg
        else:
            count += a[i] // arg - 1
    return count <= 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

n, k = MAP()
a = LIST()
if k == 0:
    print(max(a))
else:
    print(meguru_bisect(0, max(a)+1))

Solution (Python):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
ans = abs(end + start) // 2 + 1
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.0000000001)
        if cnt > K: 
            start = ans
            break
    else: 
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor((A[i] / ans) - 0.000000000001)

if cnt > K:  
    print(ans + 1)
else:  
    print(ans)

Solution (Python):
import math

def cut(l,A,K):
    counter = 0
    i = N - 1
    if l == 0:
        return False
    while i >= 0:
        c = math.ceil(A[i] / l) - 1
        if c == 0:
            break
        else:
            counter += c
            i -= 1
    if counter <= K:
        return True
    else:
        return False
    
if __name__ == '__main__':
    N,K = map(int,input().split())
    A = [float(a) for a in input().split()]
    A.sort()
    left = 0
    right = math.ceil(A[-1])
    while left <= right:
        middle = (left + right) // 2
        if cut(middle,A,K):
            if not cut(middle-1,A,K):
                break
            else:
                right = middle - 1
        else:
            left = middle + 1
    print(middle)

Solution (Python):
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        else:
            r = mid
    if f(a,l)<=k:
        print(l)
    else:
        print(r)

if __name__ == "__main__":
    main()

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans


def nibu(x,n,r):
    ll = 1
    rr = r
    while True:
        mid = (ll+rr)//2
        
        if rr == mid:
            return ll
        
        if cou(x,mid) <= n:
            rr = mid
        else:
            ll = mid+1

def cou(x,le):
    co = 0
    for i in range(len(x)):
        if le != 0:
            co += -(-x[i]//le) - 1
    return co


n,k = m()

a = l()

left = 0

right = 10**9


aaa = nibu(a,k,right)
print(aaa)

Solution (Python):
import math
def is_lt_or_e_K(k, x, a):
    if k >= sum([math.ceil(i / x) - 1 for i in a]):
        return True
    else:
        return False 
n, k = map(int, input().split())
a = list(map(int, input().split()))
high = max(a)
low = 0
while 1:
    if high - low < 2:
        break
    x = (high + low) // 2
    if is_lt_or_e_K(k, x, a):
        high = x
    else:
        low = x
print(high)

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 = 1
  high = 10**9+1
  mid = (low+high)//2
  while high>low+1:
    if check(N,mid,A,K):
      high = mid
    else:
      low = mid
    mid = (low+high)//2
  if check(N,low,A,K):
    ans = low
  else:
    ans = high
  return ans
print(solve())

Solution (Python):
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=0
r=10**9
mid=0

if(K==0):
    print(max(A))
    sys.exit(0)

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    for i in range(len(A)):
        if((A[i])%mid==0):
           tmp+=((A[i])//mid)-1
        else:
           tmp+=((A[i])//mid)
    if(tmp<=K):
        r=mid
    else:
        l=mid

print(r)

Solution (Python):
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=0
r=10**9
mid=0

if(K==0):
    print(max(A))
    sys.exit(0)

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    for i in range(len(A)):
        tmp+=((A[i]-1)//mid)
    if(tmp<=K):
        r=mid
    else:
        l=mid

print(r)

Solution (Python):
import math

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

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):

    
    x = (l+r)//2
    if x == 0:
        break

    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x
count = 0
ans = x
if(x!= 0 and l != 0):
        
    for i in range(N):
        count += math.ceil(a[i]/l)-1

    if (count <=K):
        ans = l
    else:
        ans = r

if l==0:
    ans = r
print(ans)

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

left, right = 0, max(A)
while right - left > 1:
    mid = (left + right) // 2
    res = 0
    for i in range(N):
        res = res + math.ceil(A[i]/mid) - 1
    if res <= K:
        right = mid
    else:
        left = mid
print(right)

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

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

lx = int(0)   
rx = int(1e9) 

while ((rx-lx)>1):
    x = (rx + lx) // 2
    dprint("lx, x, rx = ", lx, x, rx)
    n = 0
    for i in range(len(A)):
        
        n += (A[i]-1) // x
        if n > k: break
    dprint("n = ", n)
    if n <= k:
        dprint(" smaller x")
        rx = x
    else:
        dprint(" cut less, bigger x")
        lx = x


print(rx)

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

def cut(c):
    t = 0
    for a in A:
        if a<=c:
            continue
        t += math.ceil(a/c) - 1
    return t<=K

l=0
r=10**9
while((l+1)<r):
    c = (l+r)//2
    if cut(c):
        r = c
    else:
        l = c

print(r)

Solution (Python):
from sys import stdin
from math import floor,ceil

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

def is_max_len_less_than_input(x,K,A):
  count = 0
  for ln in A:
    count += ceil(ln/x)-1
    if count > K:
      return False
  return True

def binary_search(begin,end,K,A):
  while abs(end-begin)>1:
    mid = (begin+end)//2
    if is_max_len_less_than_input(mid,K,A):
      end = mid
    else:
      begin = mid
  return end

print(binary_search(0,max(A),K,A))

Solution (Python):
from sys import stdin
from math import floor,ceil

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

def is_max_len_less_than_input(x,K,A):
  count = 0
  if x==0:
    return False
  for ln in A:
    count += ceil(ln/x)-1
    if count > K:
      return False
  return True

def binary_search(begin,end,K,A):
  while abs(end-begin)>1:
    mid = (begin+end)//2
    if is_max_len_less_than_input(mid,K,A):
      end = mid
    else:
      begin = mid
  return end

print(binary_search(0,max(A),K,A))

Solution (Python):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
l = 0
r = 10 ** 9 + 1
while l + 1 < r:
    p = (l + r) // 2
    n = 0
    ok = False
    for v in A:
        n += (v // p - 1)
        if not v % p == 0:
            n += 1
        if n > K:
            break
    else:
        ok = True
    if not ok:
        l = p
    else:
        r = p

print(r)

Solution (Python):
import math

M=list(map(int, input().split()))
N=M[0]
K=M[1]

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

def cancut(A,N,K,X): 
    cut=0
    for a in A:
        n = (a + X - 1) // X  
        cut += n - 1
    if cut<=K:
        return 1
    else:
        return 0

left=0
right=max(A)

while(abs(right - left) > 1):
    mid=(right+left)//2
    if cancut(A,N,K,mid)==1:
        right=mid
    else:
        left=mid

print(right)

Solution (Python):
import math

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

r = 0
l = 1e9

test_count = 0

while (l - r > 1) :
    target_log_len = (r + l) // 2
    cut_count = 0

    for log_len in A:
        cut_count += (log_len - 1) // target_log_len

    if cut_count <= K:
        l = target_log_len
    else:
        r = target_log_len

    test_count += 1
    if test_count > 100:
        break

print(int(l))

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

def cut(x):
  t = 0
  for i in a:
    if i <= x:
      continue
    t += ceil(i / x) - 1
  return t <= k

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

Solution (Python):
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
from functools import reduce

def main():
    N, K = ril()
    A = ril()
    l = 1
    r = 1000000000
    while l < r:
        m = (l + r) // 2
        f = lambda i, j : i + (j - 1) // m
        k = reduce(f, A, 0)
        if k <= K:
            r = m
        else:
            l = m + 1
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N, K = ril()
    A = ril()
    l = 1
    r = 1000000000
    while l < r:
        m = (l + r) // 2
        k = 0
        for a in A:
            k += (a - 1) // m
        if k <= K:
            r = m
        else:
            l = m + 1
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):


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

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

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

print(r)

Solution (Python):
def round_up_division(num1, num2):

  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num, logs):
  search_min = 1
  search_max = search_range
  
  while True:
    
    count_a = 0
    
    count_b = 0
    
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(logs):
      
      count_a += round_up_division(A[i], half_num) - 1
      if half_num != 1:
        count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a > K:
      
      search_min = round_up_division(search_min + search_max, 2)
    elif half_num != 1 and count_b <= K:
      
      search_max = half_num - 1
    else:
      
      return half_num
      break

N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max)

Solution (Python):


import sys

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

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

p = 0
q = max(A)

if K == 0:
    print(q)
    sys.exit(0)

while q-p > 1:
    r = (p+q)//2
    count = 0
    for i in range(N):
        if A[i]/r == A[i]//r:
            count += A[i]//r - 1
        else:
            count += A[i]//r
    if count > K:
        p = r
    else:
        q = r
    

print(q)

Solution (Python):
def meg_bisect(ng, ok, func):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

n, k, *a = map(int, open(0).read().split())
print(meg_bisect(0, max(a), lambda x: sum(0--b // x - 1 for b in a) <= k))

Solution (Python):
def is_ok(arg):
    
    c = 0
    for x in a:
        c += -(-x//arg) - 1
    return c <= 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

n,k = map(int,input().split())
a = list(map(int,input().split()))
print(meguru_bisect(0,10**9+1))

Solution (Python):
import heapq
import math

def solve():
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()), reverse=True)
    l = 0
    r = A[0]
    
    
    
    while r - l> 1:
        m = (r + l) // 2
        cuts = 0
        for a in A:
            cuts += (a-1) // m
        
        if cuts <= K:
            r = m
        else:
            l = m
    print(r)

solve()