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):
def abc174_e():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    if k == 0: return max(A)

    lower, upper = 0, 10**9
    while upper - lower > 1:
        x = (upper + lower) // 2
        cnt = 0
        for a in A:
            cnt += a // x
            if a % x == 0: cnt -= 1
            if cnt > k: break
        if cnt > k: lower = x
        else: upper = x
    return upper

if __name__ == '__main__':
    print(abc174_e())

Solution (Python):
import math

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

max_l = max(A) + 1
min_l = 0
cur = (max_l + min_l) // 2


def check(l):
    count = 0
    for a in A:
        count += math.ceil(a / l) - 1

    return count <= K


while True:
    if check(cur):
        max_l = cur + 1
    else:
        min_l = cur

    if cur == (max_l + min_l) // 2:
        break

    cur = (max_l + min_l) // 2

print(cur)

Solution (Python):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n, k = rl()
    A = rl()

    def check(L):
        cuts = 0
        for a in A:
            cuts += (a - 1) // L
            if cuts > k:
                return False
        return True

    lo = 0
    hi = max(A)
    if k == 0:
        print (hi)
        return

    while lo < hi - 1:
        mid = (lo + hi) // 2
        if check(mid):
            hi = mid
        else:
            lo = mid

    print (hi)
    return








mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

A = list(map(int, input().split()))
d = [0] * N


min1 = 0
max1 = max(A) + 1

while True:
    X = (min1 + max1)//2
    for i in range(N):
        if A[i] % X == 0:
            d[i] = A[i]//X - 1
        else:
            d[i] = A[i]//X
    if sum(d) <= K:
        max1 = X 
    else:
        min1 = X
    

    if max1 - min1 <= 1:
        print(int(max1))
        break

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
low = 0
top = max(a) + 1

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

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

def possible(x):
  cut=0
  for e in maruta:
    if e%x==0:
      cut+=(e//x-1)
    else:
      cut+=e//x
  if cut<=K:
    return True
  else:
    return False

a=1
b=max(maruta)
while b-a>1:
  c=(a+b)//2
  if possible(c):
    b=c
  else:
    a=c

if possible(1):
  print(1)
else:
  print(b)

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

l, r = 0, max(a)

def ok(m):
    cut = 0
    for x in a:
        cut += (x - 1) // m
    return cut <= k

while r - l > 1:
    m = (l + r) // 2
    if ok(m):
        r = m
    else:
        l = m

print(r)

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
  if sum([(a-1)//mid for a in A])>k:
    l=mid
  else:
    r = mid
print(r)

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

def is_ok(s):
    cnt = 0
    for i in range(n):
        cnt += (A[i]-1)//s
    return cnt<=k
def main():
    left = 0
    right = max(A)
    while (right-left)>1:
        mid = (right+left)//2
        if is_ok(mid):
            right = mid
        else:
            left = mid
    return right
print(main())

Solution (Python):
import numpy as np
import math
N, K = map(int, input().split())
aaa = np.array(list(map(float, input().split())), dtype='f8')
l = 0
r = 10 ** 9
while r != l:
    mid = (r + l) // 2
    bbb = aaa / mid
    bbb -= 1
    bbb = np.ceil(bbb)
    if bbb.sum() <= K:
        r = mid
    else:
        l = mid + 1
print(l)

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

low = 1
high = max(A)

while low != high:
    mid = (low + high)// 2
    cnt = 0
    for i in A:
        cnt += math.ceil(i/mid) - 1
    if cnt > k :
        low = mid + 1
    else:
        high = mid

print(low)

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

low = 1
high = max(A)

while low != high:
    mid = (low + high)// 2
    cnt = 0
    for i in A:
        cnt += math.ceil(i/mid) - 1
    if cnt > k :
        low = mid + 1
    else:
        high = mid

print(low)

Solution (Python):
import math

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

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

low=1
high=max(A)

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


print(low)

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

ng = 0
ok = 10 ** 9





def able(x):
    count = 0
    for i in range(N):
        if A[i] % x:
            count += A[i] // x
        else:
            count += A[i] // x - 1

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


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

print(ok)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**9

def ok(l):
    cnt = 0
    for L in a:
        cnt += L//l
        if L%l != 0:
            cnt+=1
        cnt-=1
    return cnt <= k

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

Solution (Python):
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r))

Solution (Python):
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r))

Solution (Python):
import numpy as np
import sys 
N,K = map(int, input().split())
A = np.array(sys.stdin.readline().split(), np.int64)
maxa = np.max(A)
mina = maxa // (K+1)
while maxa > mina + 1:
    mid = (maxa + mina)// 2
    div = np.sum(np.ceil(A/mid-1))
    if div > K:
        mina = mid
    else:
        maxa = mid

print(maxa)

Solution (Python):
import sys
import numpy as np
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))
n,k = Mi()
a = np.array(sys.stdin.readline().split(), np.int64)
maxa = np.max(a)
mina = maxa//(k+1)
while maxa > mina+1:
  mid = (mina+maxa)//2
  div = np.sum(np.ceil(a/mid-1))
  if div > k:
    mina = mid
  else:
    maxa = mid
  
print(maxa)

Solution (Python):




n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
ng=0
ok=max(a)

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

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

Solution (Python):

import sys
N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())


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

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

Solution (Python):
import math

def solve(x):
    cnt = 0
    for i in li:
        k_i = math.ceil(i/x) - 1
        cnt += k_i
    if cnt > k:
        return False
    else:
        return True


n=0
k=0
li=[]

if __name__ == "__main__":
    n,k = map(int, input().split())
    li = list(map(int,input().split()))
    left = 1
    right = 10**9
    ans = 0
    while right >= left:
        mid = left + (right - left)//2
        flag = solve(mid)
        if flag:
            ans = mid
            right = mid - 1
        else:
            left = mid + 1
    print(ans)

Solution (Python):
def General_Binary_Search(L,R,cond,Mode=True,Integer=True,ep=1/(1<<20)):
    """一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Mode:True->広義単調増加,False->広義単調減少
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if Integer:
        if Mode:
            L-=1
        else:
            R+=1

        while R-L>1:
            C=L+(R-L)//2
            if cond(C)^Mode:
                L=C
            else:
                R=C
        if Mode:
            return R
        else:
            return L
    else:
        C=L+(R-L)/2
        while (R-C)>ep:
            if cond(C)^Mode:
                L=C
            else:
                R=C
            C=L+(R-L)/2
        return C

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

def f(x):
    r=0
    for a in A:
        r+=(a+x-1)//x
    return r-N<=K

print(General_Binary_Search(1,max(A),f,Mode=True))

Solution (Python):
def General_Binary_Search(L,R,cond,Mode=True,Integer=True,ep=1/(1<<20)):
    """一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Mode:True->広義単調増加,False->広義単調減少
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if Integer:
        R+=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C)^Mode:
                L=C
            else:
                R=C
        if Mode:
            return R
        else:
            return L
    else:
        C=(R-L)/2
        while (R-C)>ep:
            if cond(C)^(not Mode):
                L=C
            else:
                R=C
            C=L+(R-L)/2
        return C

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

def f(x):
    r=0
    for a in A:
        r+=(a+x-1)//x
    return r-N<=K

print(General_Binary_Search(0,max(A),f,Mode=True))

Solution (Python):
def General_Binary_Search(L,R,cond,Integer=True,ep=1/(1<<20)):
    """一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if Integer:
        R+=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                L=C
            else:
                R=C
        return L
    else:
        C=(R-L)/2
        while (R-C)>ep:
            if cond(C):
                L=C
            else:
                R=C
            C=L+(R-L)/2
        return C

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

def f(x):
    r=0
    for a in A:
        r+=(a+x-1)//x
    return r-N

print(-General_Binary_Search(-max(A),-1,lambda x:f(-x)<=K))

Solution (Python):
import math

def check(A, x, k):
    cut_count = 0
    for number in A:
        cut_count += (math.ceil(number / x)) -1
    return cut_count <= k

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

l = 0
r = 10 ** 9
 
while r - l > 1:
    x = (r + l) // 2
  
    if check(a, x, k):
        r = x
    else:
        l = x   
print(r)

Solution (Python):
import math

def is_ok(A, x, K):
  cut_count = 0
  for number in A:
    cut_count += (math.ceil(number / x)) - 1
  return cut_count <= K

A = []
[N, K] = input().split()
N = int(N)
K = int(K)
A = input().split()
ans = 0

l = 0
r = 10 ** 9

for i in range(N):
  A[i] = int(A[i])

while r - l > 1:
  x = (r + l) // 2
  if is_ok(A, x, K):
    r = x
  else:
    l = x
      
print(r)

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


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


l = 0
r = max(A)

while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

Solution (Python):
from math import ceil
N,K =map(int,input().split())
A = list(map(int,input().split()))
X1 = 1
X2 = 10**9
while X1 != X2-1:
    X = ceil((X1 + X2)/2)
    S = 0
    for i in range(N):
        S += ceil(A[i]/X) - 1
    if S <= K:
        X2 = X
    else:
        X1 = X
S1 = 0
for i in range(N):
    S += ceil(A[i]/X2) - 1
if S <= K:
    X2 = X1
print(X2)

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

    def isOK(x):
        count = sum((a-1)//x for a in A)
        if count <= K:
            return True
        else:
            return False

    def binary_search(init_l, init_r):
        """(l, r]"""
        left = init_l
        right = init_r

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

        return right
    
    sum_A = sum(A)
    max_ans = (sum_A + K)//(K+1)
    min_ans = (sum_A + K+N-1)//(K+N)
    ans = binary_search(min_ans-1, max_ans)
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
def f(x):
    now = 0
    for i in range(n):
        now += (a[i]-1)//x

    return now <= k

n, k = map(int, input().split())
a = list(map(int, input().split()))
ng = 0
ok= int(1e9)
while ok - ng > 1:
    x = (ok + ng) // 2
    if f(x):
        ok = x
    else:
        ng = x

print(ok)

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

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

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):
import numpy as np
import numba


@numba.njit
def count(a_arr, bar):
    
    res_arr = ((a_arr - 1) // bar)
    new_bar = (a_arr / (res_arr + 1)).max()
    return res_arr.sum(), np.int(np.ceil(new_bar))


def solve(n, k, a_arr):
    left_bar = ((a_arr - 1) // (k + 1)).min()
    right_bar = a_arr.max()
    while True:
        mid_bar = (left_bar + right_bar) // 2
        
        m, mid_bar_new = count(a_arr, mid_bar)

        if m > k:
            left_bar = mid_bar
        else:
            right_bar = mid_bar_new

        if left_bar > right_bar - 2:
            break
    return right_bar


def main():
    n_, k_ = map(int, input().split())
    n = np.int32(n_)
    k = np.int32(k_)
    a_arr = np.array(list(map(int, input().split())), dtype=np.int32)
    res = solve(n, k, a_arr)
    print(res)


def test():
    assert solve(2, 3, np.array([7, 9])) == 4
    assert solve(3, 0, np.array([3, 4, 5])) == 5
    assert solve(10, 10, np.array([
        158260522, 877914575, 602436426, 24979445, 861648772,
        623690081, 433933447, 476190629, 262703497, 211047202
    ])) == 292638192


if __name__ == "__main__":
    test()
    main()

Solution (Python):
import math

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

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

middle = math.ceil(max(a) / 2)
oldMiddle = 0
h = middle // 2
rightMin = max(a)

while h > 0:
    cut = 0
    if middle == 0:
        middle = 1
        break
    for i in range(n):
        cut += math.ceil(a[i] / middle) - 1
    h = math.ceil(abs(middle - oldMiddle) / 2)
    oldMiddle = middle
    if cut <= k:
        if (middle - h == rightMin):
            break
        middle -= h
    else:
        rightMin = middle
        middle += h

print(middle)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ok = 10**9
ng = 0
while ng+1 < ok:
    tmp = (ok+ng)//2
    k = 0
    for a in A:
        if a%tmp == 0:
            k += a//tmp -1
        else:
            k += a//tmp
    if k <= K:
        ok = tmp
    else:
        ng = tmp
print(ok)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
left = 0
right = max(A)
while(right - left > 1 and K != 0):
    x = (right + left) // 2
    def min_cut(x: int):
        n = 0
        for a in A:
            n += (a - 1) // x
        return n <= K
    if min_cut(x):
        right = x
    else:
        left = x
print(right)

Solution (Python):
'''
Date         : 2020-08-09 00:46:52
Author       : ssyze
Description  : 
'''
n, k = map(int, input().split())
a = list(map(int, input().split()))


def check(m):
    sum = 0
    for i in range(len(a)):
        sum += (a[i] - 1) // m
    if sum > k:
        return False
    else:
        return True


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

Solution (Python):



from math import ceil

def main():
  n, k = map(int, input().strip().split())
  la = list(map(int, input().strip().split()))
  la.sort()
  
  def check(x):
    cnt = 0
    for a in la:
      cnt += ceil(a / x) - 1
      if cnt > k:
        return False
    return True
 
  def bs(s, t):
    while ceil(s) != ceil(t):
      x = (s + t) / 2
      if check(x):
        t = x
      else:
        s = x
    return ceil(x)
  
  s, t = 0, 10 ** 9
  print(bs(s, t))
  
if __name__=='__main__':
  main()

Solution (Python):
import sys
import math

input = sys.stdin.readline

def can(arr, m, K):
  need = 0
  for x in arr:
    if x > m:
      need += int(x // m)
  return need <= K

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

lo = 1
hi = int(1e9) + 1

while (lo < hi):
  m = int((lo + hi) // 2)
  if (can(arr, m, K)):
    hi = m
  else:
    lo = m + 1
print(lo)

Solution (Python):
import sys
import math

input = sys.stdin.readline

def can(arr, m, K):
  need = 0
  for x in arr:
    if x > m:
      need += int(x // m)
  return need <= K

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

lo = 1
hi = int(1e9) + 1

while (lo < hi):
  m = int((lo + hi) // 2)
  if (can(arr, m, K)):
    hi = m
  else:
    lo = m + 1
print(lo)

Solution (Python):
import math

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

    def _f(length: int) -> bool:
        count = 0
        for a in A:
            count += int((a-1) / length)
        return count <= K

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

if __name__ == "__main__":
    resolve()

Solution (Python):
def min_cut_num(n, L, size):
    cnt = 0
    for wood in L:
        cnt += ((wood + size - 1) // size) - 1
    return cnt
    

def main():
    n, k = map(int, input().split())
    L = list(map(int, input().split()))
    
    left = 0
    right = 10 ** 9    
    while right - left > 1:
        mid = (left + right) // 2
        if min_cut_num(n, L, mid) <= k:
            right = mid
        else:
            left = mid
    print(right)




if __name__ == '__main__':
    main()

Solution (Python):
import math

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

def cond(x):
    s = 0
    for i in range(n):
        s += math.ceil(a[i]/x)-1
    return s <= k

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

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

l, r = (A[0], 1)
def is_ok(c):
    x = sum([math.ceil(a/c)-1 for a in A])
    return x <= K

l, r = max(A), 0
while l - r > 1:
    c = (l + r) // 2
    if is_ok(c):
        l = c
    else:
        r = c
print(l)

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

l,r = 1,max(A)
while l<r:
	m = (l+r)//2
	s = sum([a//m+(not a%m==0)-1 for a in A])
	if s <= K:
		r = m
	else:
		l = m+1
print(r)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=0,max(a)
def test(x):
  num=0
  for i in a:
    num+=i//x
    if i%x==0:
      num-=1
  if num<=k:
    return num
while r-l>1:
  mid=(l+r)//2
  if test(mid):
    r=mid
  else:
    l=mid
print(r)

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

l , r = 0, max(a)

def ok(L):
  cnt = 0
  for i in a:
    cnt += i // L
    if i % L == 0:
      cnt -= 1
  return cnt <= k

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

  if ok(mid):
    r = mid
  else:
    l = mid

print(r)

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

    left = 0
    right = max(A)

    while abs(right-left)>1:
        cent = (right+left)//2
        
        ct = 0
        for a in A:
            ct+=a//cent
            if a%cent==0:
                ct-=1
        
        if ct <= k:
            right=cent
        else:
            left=cent
    
    print(right)
main()

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

    left = 0
    right = max(A)

    while abs(right-left)>1:
        cent = (right+left)//2
        
        ct = 0
        for a in A:
            ct+=a//cent
            if a%cent==0:
                ct-=1
        
        if ct <= k:
            right=cent
        else:
            left=cent
    
    print(right)
main()

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

    left = 0
    right = max(A)

    while abs(right-left)>1:
        cent = (right+left)//2
        
        ct = 0
        for a in A:
            ct+=(a-0.1)//cent
        
        if ct <= k:
            right=cent
        else:
            left=cent
    
    print(right)
main()

Solution (Python):
n,k=map(int, input().split())
A=[int(i) for i in input().split()]
ng=0
ok = max(A)
while(ng+1!=ok):
    mid = (ok+ng)//2
    ans = 0
    for i in A:
        ans += 0--i//mid-1
    if(ans<=k):
        ok = mid
    else:
        ng = mid
print(ok)

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

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

ng = 0
ok = 10**9
while 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()))

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

ng = 0
ok = max(A)
while 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()))

def is_ok(n):
    cnt = 0
    for a in A:
        if n >= a:
            continue
        cnt += a // n
    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+1))

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

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

lower = 0
upper = max(L)

while upper - lower > 1:
    mid = (lower + upper)//2
    if A(mid):
        upper = mid
    else:
        lower = mid

print(upper)

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

l = 0
r = 1000000000

def judge(m):
    k = 0
    for i in range(N):
        if A[i]%m==0:
            k+=A[i]//m-1
        else:
            k+=A[i]//m
    return k<=K

while r-l>1:
    if judge((l+r)//2):
        r = (l+r)//2
    else:
        l = (l+r)//2
print(r)

Solution (Python):
n,k=map(int,input().split())
arr=list(map(int,input().split()))
def isvalid(mid,k):
    if mid==0:
        return False
    ans=k
    for i in arr:
        if i>mid:
            ans-=i//mid
    return ans>=0


l=0
r=10**9
while(l<r):
    mid=(l+r)//2
    if isvalid(mid,k):
        r=mid
    else:
        l=mid+1
print(l)

Solution (Python):
from bisect import *
from heapq import *
import math
mod = 10**9+7
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = 10**9+1
while l+1 < r:
    x = (l+r)//2
    k = 0
    for a in A:
        k += math.ceil(a/x)-1
        if k > K:
            break
    if K < k:
        l = x
    else:
        r = x
print(r)

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


ng = 0
ok = max(logs)
while abs(ok-ng)>1:
  times = 0
  mid = (ok+ng)//2
  for A in logs:
    times += math.ceil(A/mid)-1
    
    
  if times <= K:
    ok = mid
  else:
    ng = mid
    
print(ok)

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


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

l = 0
r = 10**9

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

Solution (Python):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
l=list(map(int,input().split()))
ok=max(l)
ng=0
def solve(m):
    s=0
    for i in l:
        s+=-((-i)//m)-1
    return s

while ok-ng>1:
    m=(ok+ng)//2
    if k<solve(m):
        ng=m
    else:
        ok=m
print(ok)

Solution (Python):
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while b-a > 1:
    c = (a+b)//2
    times = []
    for i in logs:
        times.append(math.ceil(i/c)-1)
    if sum(times) > K:
        a = c
    else:
        b = c

print(b)

Solution (Python):
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while math.ceil(a) != math.ceil(b):
    c = (a+b)/2
    times = []
    for i in logs:
        times.append(math.floor(i/c))
    if sum(times) > K:
        a = c
    else:
        b = c
    if b - a < 0.001:
        count +=1
    if count >20:
        flg+=1
        break
if flg == 0:         
    print(math.ceil(b))
else:
    a = math.ceil(a)
    times = []
    for j in logs:
        times.append(math.floor(i/a))
    if sum(times) > K:
        print(math.ceil(b))   
    else:
        print(math.ceil(a))

Solution (Python):
from math import *
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
def is_ok(arg):
    tmp=0
    for i in a:
        tmp+=ceil(i/arg)-1
    return tmp<=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, max(a)))

Solution (Python):
from bisect import bisect
import math
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:
    cnt += math.ceil(a/mid) - 1
  
  if cnt <= k:
    r = mid
  else:
    l = mid
print(r)

Solution (Python):
from sys import stdin
input = stdin.buffer.readline
n, k = map(int, input().split())
*a, = map(int, input().split())
def f(mx):
    cnt = 0
    for i in a:
        cnt += (i + mx - 1) // mx - 1
    return cnt
l, r = 1, int(1e9)
while l < r:
    m = (l + r) >> 1
    if f(m) > k:
        l = m + 1
    else:
        r = m
print(r)

Solution (Python):
import math

def ok(l):
    x =sum([math.ceil(a/l) -1 for a in A])
    if x <=K:
        return True
   
    


import bisect
import sys
input = sys.stdin.readline  
N,K = map(int, input().split())
A = list(map(int, input().split()))


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

Solution (Python):

import math

N,K = map(int,input().split())
A   = list(map(int,input().split()))
Amax = int(max(A))
high = Amax
Cancut = Amax
low  = 0
while ( (high - low) > 0.01 ) :
    Cut = 0
    X = (high + low) / 2.0
    for i in range(N):
        Cut = Cut + math.ceil(A[i]/X) - 1
    if Cut <= K:
        high = X
        Cancut = X
    else:
        low  = X

if (math.floor(high) != math.floor(low)):
    Cancut = math.floor( 100 * Cancut) /100.0
print(math.ceil(Cancut))

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=0
b=10**9+1
while a+1<b:
  mid=(a+b)//2
  ans=0
  for i in A:
    ans+=(i-1)//mid
  if K<ans:
    a=mid
  else:
    b=mid
print(b)

Solution (Python):
def main():
    _, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    if K == 0:
        print(max(A))
        return

    def is_ok(x):
        need = 0
        for a in A:
            if a % x == 0:
                need += a//x - 1
            else:
                need += a//x
        if need <= K:
            return True
        else:
            return False

    def binary_search():
        ng = 0
        ok = 10**9
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search())


if __name__ == '__main__':
    main()