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 = map(int, input().split())
A = list(map(int, input().split()))

lower = 0
upper = max(A)
mid = math.ceil((lower + upper) / 2)
while lower < upper:
    mid = math.ceil((lower + upper) / 2)
    if mid == upper:
        break
    # print(lower, mid, upper)
    cut = 0
    for a in A:
        cut += math.ceil(a / mid) - 1
    if cut <= K:
        upper = mid
    else:
        # K < cut
        lower = mid

print(mid)

Submission status: Accepted

Solution code:
import math, sys

N,K = map(int,input().split())
A = [int(x) for x in input().split()]
lower = 0
upper = 10**10

while upper - lower > 0.1:
    cuts = 0
    trial = (lower + upper) / 2
    for i in A:
        cuts += math.ceil(i/trial)-1
    if cuts <= K:
        upper = trial
    else:
        lower = trial
ans = math.ceil(lower)
if ans == 0:
    print(1)
    sys.exit()
cuts = 0
for i in A:
    cuts += math.ceil(i / ans) - 1
if cuts <= K: print(ans)
else: print(ans + 1)

Submission status: Accepted

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

def isok(x):
  c=0
  for i in range(N):
    c+=math.ceil(A[i]/x)-1
  if c<=K:
    return True
  else:
    return False
start=0
end=max(A)
mid=(start+end)//2
while end-start>1:
  mid=(start+end)//2
  if isok(mid)==True:
    end=mid
  else:
    start=mid
print(end)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(0).read().split())
l,r=0,10**9
while~l+r:
 x=l+r>>1
 if-sum(-b//x+1for b in a)>k:l=x
 else:r=x
print(r)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:
 x=l+r>>1
 if-sum(-b//x+1for b in a)>k:l=x
 else:r=x
print(r)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(0).read().split())
ok=10**9
ng=0
while ok-ng>1:
  x=ok+ng>>1
  if-sum(-b//x+1for b in a)>k:ng=x
  else:ok=x
print(ok)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ar=list(map(int,input().split()))
def cnt(x):
	s=0
	for i in ar:
		if i>x:
			s+=(i-1)//x
	return s
l=0
r=10**9
while l<r-1:
	m=(l+r)//2
	c=cnt(m)
	if c>k:
		l=m
	else:
		r=m
print(r)

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase
from math import ceil

def possible(logs, k, ans):
    for l in logs:
        k -= ceil(l/ans) - 1
    return k>=0


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

    l = 1
    r = max(logs) + 1

    while l < r:
        mid = (l + r)//2
        if possible(logs, k, mid):
            r = mid
        else:
            l = mid + 1
    print(l)




        




































# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
 
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
*A, = map(int, input().split())
a, b = 0, 10**9
while b - a > 1:
    x = (a + b) // 2
    cut = 0
    for i in range(n):
        cut += -(-A[i] // x) - 1
    if cut <= k:
        b = x
    else:
        a = x
print(b)

Submission status: Accepted

Solution code:
import numpy as np

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

left, right = 0, np.max(a)
while right - left > 1:
    mid = left + (right - left) // 2
    if np.sum(np.ceil(a/mid)-1) <= k:
        right = mid
    else:
        left = mid
print(right)

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  l.sort()

  left=0
  right=10**9

  while right-left>1:
    middle=(left+right)//2

    cnt=0
    for x in l:
      cnt+=(x+middle-1)//middle-1

    if cnt<=k:
      right=middle
    else:
      left=middle

    # print(left,middle,right)

  return right

# main()
print(main())

Submission status: Accepted

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


def check(l):
    cnt = 0
    for L in a:
        cnt += L // mid
        if L % mid != 0:
            cnt += 1
        cnt -= 1

    return cnt <= k


lb, ub = 0, max(a)
while ub - lb > 1:
    mid = (ub + lb) // 2

    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Accepted

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


def check(l):
    cnt = 0
    for i in range(n):
        cnt += a[i] // mid
        if a[i] % mid != 0:
            cnt += 1
        cnt -= 1

    return cnt <= k


lb, ub = 0, max(a)
while ub - lb > 1:
    mid = (ub + lb) // 2

    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Accepted

Solution code:
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    sumA=sum(A)
    K_i=[int(A[i]/sumA*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

a.sort()
r = a[n-1]
l = 0


def calc(t,x):
    return (t-1) // x


while r - l > 1:
    mid = (r+l)//2
    count = 0
    for i in a:
        count += calc(i,mid)
    if count > k:
        l = mid
    else:
        r = mid

print(r)

Submission status: Accepted

Solution code:
import math

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

a.sort()
r = a[n-1]
l = 0


def calc(t,x):
    return math.ceil(t / x) - 1


while r - l > 1:
    mid = (r+l)//2
    count = 0
    for i in a:
        count += calc(i,mid)
    if count > k:
        l = mid
    else:
        r = mid

print(r)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

OK = 10**12
NG = 0

while OK-NG > 1:
    mid = (OK+NG)//2
    cnt = 0
    for a in A:
        cnt += (a-1)//mid
    if cnt <= K:
        OK = mid
    else:
        NG = mid
    # print('OK:{}, NG:{}, cnt:{}'.format(OK, NG, cnt))

print(OK)

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
a = list(map(int,input().split()))
def is_ok(arg):
    i = 0
    for item in a:
        i += math.ceil(item /arg) -1
    return i <=K

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(0,10**9))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
L, R = 0, A[-1]
while R - L > 1:
    mid = L + (R - L) // 2
    if sum([(a - 1) // mid for a in A]) <= K:
        R = mid
    else:
        L = mid
print(R)

Submission status: Accepted

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

def check(m):
  return sum([ (a+m-1)//m  - 1 for a in A ]) <= K

def main():
  l = 0
  r = max(A)
  
  while l + 1 < r:
    m = (l + r) // 2
    is_over = check(m)
    
    if is_over:
      r = m
    else:
      l = m
  return  r
  
print(main())

Submission status: Accepted

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

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

l = 0
u = max(a)

while u > l+1:
#    print(l,u)
    c = (l + u) // 2
    cnt = 0
    for i in a:
        cnt = cnt + ((i-1)//c)
    if cnt <= k:
        u = c
    else:
        l = c

print(u)

Submission status: Accepted

Solution code:

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

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

left = 0
right = 10 ** 9
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

Submission status: Accepted

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

def check(x):
    cnt = 0
    for ai in a:
        cnt += (ai-1)//x
        if cnt > k:
            return False
    return True

left = 0
right = 10**9+1
while right-left>1:
    mid = (right+left)//2
    if check(mid):
        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()))

def ink(L):
    cnt = 0
    for i in range(N):
        cnt += A[i]//L
        if A[i]%L != 0:
            cnt += 1
        cnt -= 1
    return cnt <= K

bottom, top = 0, max(A)

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

print(top)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if ans==ceil(mid):
                flag=True
        ans=min(ans, ceil(mid))
        right=mid
        
        #if flag:
        #    break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, ceil(mid))
        right=mid
        pre=mid
    count+=1
    if count>=10**2:
        break
    


if ans==float("INF"):
    ans=max(A)
print(ceil(ans))

Submission status: Accepted

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

right = 10**9
left=0

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

Submission status: Accepted

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

def c(x):
    cnt=0
    for i in a:
        cnt += (i - 1) // x
    return cnt <= k
    
l, r = 0, max(a)
while l + 1 < r:
    mid = (l + r) // 2
    if c(mid):
        r = mid
    else:
        l = mid

print(r)

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, K = next(it), next(it)
    A = list(it)
    A.sort(reverse=True)

    def ok(n):
        k = K
        for ai in A:
            if ai <= n:
                return True

            a, b = divmod(ai, n)
            if b == 0:
                a -= 1
            k -= a
            if k < 0:
                return False
        return True


    lo, hi = 1, A[0]
    while lo < hi:
        mi = (lo+hi)//2

        if ok(mi):
            hi = mi
        else:
            lo = mi+1

    print(hi)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import math

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

#  めぐる式二分探索で実装

def calc(x):
    count = 0
    for a in A:
        count += (a - 1) // x

    return count <= K

ok = 10 ** 9
ng = 0

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

print(ok)

Submission status: Accepted

Solution code:
import math

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

#  にぶたん！ 半開区間二分探索は正義

def calc(x):
    count = 0
    for a in A:
        count += (a - 1) // x

    return count <= K

A.sort(reverse=True)

r = 10 ** 9
l = 0

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

print(r)

Submission status: Accepted

Solution code:
def e_logs():
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    def ceil_int(p, q):
        """p/q の切り上げ"""
        return (p + q - 1) // q

    def calc(x):
        """K 回以内のカットですべての丸太の長さを x 以下にできるか？"""
        return sum(ceil_int(a, x) - 1 for a in A) <= K

    # 全丸太の長さは、0 以下にはできないし、max(A) には必ずできる (どれも切らない)
    reject, accept = 0, max(A)
    while accept - reject > 1:
        mid = (accept + reject) // 2
        if calc(mid):
            accept = mid
        else:
            reject = mid
    return accept

print(e_logs())

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    l, r = 0, max(A)
    while r - l > 1:
        c = (l + r) // 2
        if sum((a - 1) // c if a > c else 0 for a in A) <= k:
            r = c
        else:
            l = c
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

right=10**9
left=0

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

print(right)

Submission status: Accepted

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


def f(i):
    if i<=0: return False
    if i>= 10**9: return True
    x = sum([(a-1)//i for a in A])
    if x<=k:
        return True
    else:
        return False
l=-1
r=10**9
while r-l>1:
    m = (l+r)//2
    if f(m):
        r=m
    else:
        l=m
    #print(l,m,r)
print(r)

Submission status: Accepted

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

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

def f(x):
    cnt = 0
    for i in A:
        if i % x == 0:
            cnt += i//x - 1
        else:
            cnt += i//x
    
    if cnt <= K:
        return True
    else:
        return False


A_max = max(A)
ok = 0
ng = A_max
from math import log2, ceil
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ng = mid
    else:
        ok = mid
print(ceil(ng))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
result = max(a)
left = 1
right = result
med = left + (right - left) // 2
while left <= right:
    counter = sum([(x - 1) // med for x in a])
    if counter <= k:
        result = med
        right = med - 1
    else:
        left = med + 1
    med = left + (right - left) // 2
print(result)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [x * 2 for x in a]
result = max(a)
left = 1
right = result
med = left + (right - left) // 2
while left <= right:
    counter = sum([(x - 1) // med for x in a])
    if counter <= k:
        result = med
        right = med - 1
    else:
        left = med + 1
    med = left + (right - left) // 2
print((result + 1) // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
tree = list(map(int, input().split()))
left = 0
right = max(tree)

while right - left > 1:
    cnt = 0
    mid = (right + left) // 2
    for i in tree:
        cnt += i // mid
        if i % mid == 0:
            cnt -= 1  # ちょうどに切れるときは切り口が1減る
    if K >= cnt:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
tree = list(map(int, input().split()))
left = 0
right = 2*(10**9)
treeLen = len(tree)

while right - left > 1:
    cnt = 0
    mid = (right + left) // 2
    for i in range(treeLen):
        cnt += tree[i] // mid
        if tree[i] % mid == 0:
            cnt -= 1  # ちょうどに切れるときは切り口が1減る
    if K >= cnt:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
an = list(map(int, input().split()))

maxi = max(an)
if k == 0:
    print(maxi)
    exit(0)


def judge(t):
    m = 0
    for i in an:
        if i%t == 0:
            m +=i//t
        else:
            m += i//t+1
    #print('judge', m, n+k)
    if m <= n+k:
        #print("true")
        return True
    else:
        #print("false")
        return False

mini = 0
#maxi = max(an)

while mini+1 != maxi:
    check = (mini+maxi)//2
    #print(check)
    if judge(check):
        maxi = check
        #print(mini, maxi)
    else:
        mini = check
        #print(mini, maxi)

print(maxi)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

def check(x, lst, k):
    cnt = 0
    for l in lst:
        cnt += (l - 1) // x
    if cnt  <= k:
        return True
    else:
        return False
    

def main():
    input = sys.stdin.readline
    
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    def check(x):
        cnt = 0
        for l in a:
            cnt += (l - 1) // x
        if cnt  <= k:
            return True
        else:
            return False
    
    ng = 0
    ok = 10 ** 9
    
    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:
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
  print(max(A))
  exit()
def f(x):
  cnt=0
  for i in A:
    if i%x==0:
      cnt+=i//x-1
    else:
      cnt+=(i//x)
  if cnt<=K:
    return True
  else:
    return False
ok=1
ng=1000000000
for i in range(50):
  mid=(ok+ng)//2
  if f(mid):
    ng=mid
  else:
    ok=mid
print(ng)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

def check(x, lst, k):
    cnt = 0
    for l in lst:
        cnt += (l - 1) // x
    if cnt  <= k:
        return True
    else:
        return False
    

def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ng = 0
    ok = 10 ** 9
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid, a, k):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#from functools import lru_cache
import sys
import math
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))
def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())
sys.setrecursionlimit(100000)
ls = rvfunc(int)(reader())
n,k=ls[0]
a=ls[1]

def reqk(l):
    return sum(vfunc(lambda aa:math.ceil(aa/float(l))-1)(a))
def binary_search(imin=None,imax=None):
    if [imin,imax]==[None]*2: imin,imax=1,10**9+1
    if (imax < imin):
        return imin
    else:
        imid = int(imin + (imax - imin) / 2)
        if (reqk(imid)<=k):return binary_search(imin, imid - 1)
        elif (reqk(imid)>k):return binary_search(imid + 1, imax)
print(binary_search() if k!=0 else max(a))

Submission status: Accepted

Solution code:

def isok(A, X, k):
    cnt = 0
    for a in A:
        cnt += (a+X-1)//X-1
    return True if cnt <= k else False


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

# 答えを二分探索
left = 0 # 条件をみたさない
right = 10**9 # みたす

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

print(right)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math
 
N, K = mi()
A = li()

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

left = 0
right = max(A)
 
def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num) - 1
    return cnt
'''
while True:
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        break
    tmp = count(mid)
    if right - left <= 1:
        print(right)
        exit()
    elif tmp > K:
        left = mid
    else:
        right = mid
'''

def is_ok(arg):
    if count(arg) <= K:
        return True
    else:
        return False
    

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, right+1))

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]
    if(k == 0):
        print(MA)
        return
    while(True):
        m = mi + (MA - mi)//2
        if(MA == 1):
            print(1)
            return
        count = 0
        for i in a:
            plus = i//m - 1 if i%m == 0 else i//m 
            count += plus
        if(MA - mi <= 0):
            if(k >= count):
                print(m)
            else:
                print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m
        





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
import math

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K == 0:
        print(max(A))
        exit()
    
    # 二分探索で答えxを求める
    MIN = 0
    MAX = max(A)

    while MAX - MIN > 1:
        MID = (MIN + MAX)//2
        cnt = 0
        for i in range(N):
            cnt += (A[i]-1)//MID
        if cnt <= K:
            MAX = MID
        else:
            MIN = MID
    print(MAX)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math as mt
n,k=map(int,input().split())
a=list(map(int,input().split()))
bot=0
top=max(a)


while 1:
  cen=(top+bot)//2
  x=0
  if cen==0:
    print(1)
    break
  for i in a:
    x+=mt.ceil(i/cen)-1
  #print(x,top,cen,bot)
  if x>k:
    bot=cen+1
  else:
    top=cen
  
  if top<=bot:
    print(top)
    break
  if bot==cen:
    print(cen+1)
    break

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math
 
N, K = mi()
A = li()
 
if K == 0:
    print(max(A))
    exit()
 
left = 0
right = max(A)
 
def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num) - 1
    return cnt
 
while True:
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        break
    tmp = count(mid)
    if right - left <= 1:
        print(right)
        exit()
    elif tmp > K:
        left = mid
    else:
        right = mid

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from bisect import bisect_left

n, k = map(int, input().split())
*a, = map(int, input().split())
def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    return sum(-(-i // arg) - 1 for i in a) <= k


def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
print(meguru_bisect(0, max(a)))

Submission status: Accepted

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

min_num = 1
max_num = 10**9+1
while True:
    #print(min_num)
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    #print(x)
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(min_num+1)
else:
    print(min_num)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
max_a = 10**9
min_a = 0

while max_a-min_a>1:
    count = K
    mean_a = (max_a+min_a)//2
    for i in range(N):
        count -= -(-a[i]//mean_a)-1
    if count >= 0:
        max_a = mean_a
    else:
        min_a = mean_a

print(max_a)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
max_a = 10**9
min_a = 0

while max_a-min_a>1:
    count = K
    mean_a = (max_a+min_a)//2
    
    for i in range(N):
        if a[i]<=mean_a: continue
        count -= a[i]//mean_a
    if count >= 0:
        max_a = mean_a
    else:
        min_a = mean_a

print(max_a)