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



Sample input:
2 3
7 9


Sample output:
4

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
from math import ceil
# 小数点以下を繰り上げた値を出力するので，最大長さを整数の中 (0からmax(A)の間) から探す． (これをxとする)
# すべての本数をxより小さくするまでの回数がK以下であれば良い．

def main(N, K, A):
    # 二分探索内で用いる判定用関数
    def check(x):   # すべての長さをx以下にするための回数
        cnt = 0 # すべての長さをx以下にするために何回切ったか
        for a in A:
            cnt += ceil(a / x) - 1  # 切り口は1つ少ない
        return cnt <= K # K回以内で操作を終えることができたかどうか．

    l, r = 0, max(A)    # この中をxが動く．
    while l < r - 1:    # 差が1未満 == lとrが隣り合わせ == rができる最小， lができない最大を示し，それらが隣り合わせ
        mid = (l + r) // 2
        if check(mid): # 真ん中の条件でも終えることができるならそれよりも小さくできるので， r (最大方向) を縮める．
            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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
#最大の最小値を求める問題は二部探索
#最大の最小値がちょうどokとngの境界になる
#求める値をlとするとその長さに全ての丸太をきるのに必要な回数を数えることができる
#その丸太をきる回数がk回以下であればいい
#絶対にだめ→０　絶対にオッケー→max(a)
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
#丸太をきる回数がk回以下かどうか調べる関数
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:

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

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

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
#全丸太の長さはk回以内の操作でright以下にできる
while right != left + 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
alist=list(map(int,input().split()))
#print(alist)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
(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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)
  #print(l,m,r,kk)
  if kk <= k:
    r = m
  else:
    l = m
  count += 1
print(math.ceil(l))

Submission status: Accepted

Solution code:
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, min_tree,tmp_count)
print(max_tree)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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
        # print(cnt)
    return cnt <= k


# print(judge(4))
# print(judge(5))
# print(judge(3))

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# template: v1.3.1

# 丸太の分割分割問題。
# 速度の観点から、「答えの二分探索」が必要。典型らしい。
# f(x) の処理、すぬけさんのをチェック


import io
import sys
import math

### DEBUG ###
_DEB = 0   # 1:ON / 0:OFF

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

# Worst
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"


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


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

# is_m_OK?
def f(m):
    cut=0
    for aa in a:
        #ここを変えた
        c=(aa-1)//m 
        cut+=c
        if cut > k:
            return False
    return True
#m=7,a=[7,9]


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

### Solve ####
def solve():
    # Process

    ans=0
    l,r=0,10**9
    while abs(r-l)!=1:
        m=(l+r)//2
        if f(m): # m is ok: Go left
            r=m
        else: # m is ng : Go right
            l=m
    
    ans=r
    # ans=min(r,max(a))

    # OUPUT
    ans = str(ans)
    print(ans)
    return ans

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# template: v1.3.1

# 丸太の分割分割問題。
# 速度の観点から、「答えの二分探索」が必要。典型らしい。



import io
import sys
import math

### DEBUG ###
_DEB = 0   # 1:ON / 0:OFF

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

# Worst
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"
# _INPUT = f"{str(2*(10**5))} {str(10**9)}\n{(str(10**9)+' ')*(2*(10**5)) }"


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


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

# is_m_OK?
def f(m):
    cut=0
    for aa in a:
        c=math.ceil(aa/m)
        cut+=c-1
        if cut > k:
            return False
    return True
#m=7,a=[7,9]


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

### Solve ####
def solve():
    # Process

    ans=0
    l,r=0,10**9
    while abs(r-l)!=1:
        m=(l+r)//2
        if f(m): # m is ok: Go left
            r=m
        else: # m is ng : Go right
            l=m
    
    ans=r
    # ans=min(r,max(a))

    # OUPUT
    ans = str(ans)
    print(ans)
    return ans

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

l, r = 0, int(1e9)

def count_cut(log, size):
    return (log - 1) // size

while r - l > 1:
    pivot = (r + l) // 2
    count = sum(count_cut(log, pivot) for log in logs)

    if K < count:
        l = pivot
    elif count <= K:
        r = pivot

print(r)

Submission status: Accepted

Solution code:
n, k, *aa = map(int, open(0).read().split())

imp_length = 0
psbl_length = max(aa)

while psbl_length - imp_length > 1:
    mid = (psbl_length + imp_length) // 2
    cost = sum(0 - -a // mid - 1 for a in aa)
    if cost <= k:
        psbl_length = mid
    else:
        imp_length = mid

print(psbl_length)

Submission status: Accepted

Solution code:
from math import ceil
from fractions import Fraction

n, k, *aa = map(Fraction, open(0).read().split())

imp_length = 0
psbl_length = max(aa)

while psbl_length - imp_length > 1:
    mid = (psbl_length + imp_length) // 2
    cost = sum(ceil(a / mid) - 1 for a in aa)
    if cost <= k:
        psbl_length = mid
    else:
        imp_length = mid

print(psbl_length)

Submission status: Accepted

Solution code:
from math import ceil

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

left = 0
right = max(aa)

while right - left > 1:
    mid = (left + right) // 2
    summ = sum(0--a//mid-1 for a in aa)
    if summ <= k:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

Solution code:
from math import ceil

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

left = 0
right = 10**9

while right - left > 1:
    mid = (left + right) // 2
    summ = sum(0--a//mid-1 for a in aa)
    if summ <= k:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

Solution code:
import math

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

hq = []

def is_ok(checking):
    cost = 0
    for i in range(n):
        cost += math.ceil(a[i]/checking)-1
    if cost <= k:
        return True
    else:
        return False

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

ok = meguru_bisect(0, int(1e+10)) 
print(int(ok))
# 初期値の範囲は取りえる値-1～+1とする←範囲内はok,ngどちらもあり得るため