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 sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()
A = LMI()

A.sort(reverse=True)

def split_cnt(L):
    cnt = 0
    for a in A:
        if a <= L:
            break
        cnt += -(-a // L) - 1
    return cnt



l = 0
r = A[0]
while l + 1< r:
    mid = (l + r) // 2
    if split_cnt(mid) <= K:
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

Solution code:
import copy
import math

def judge(As,K,C):
    count = 0
    for i in range(len(As)):
        if As[i]%C == 0:
            m = As[i]//C - 1
        else:
            m = As[i]//C
        count += m
    if count <= K:
        return True
    else:
        return False

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

l = 0
r = max(As)
while(r-l>1):
    mid = (l+r)//2
    if judge(As,K,mid):
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

Solution code:
def judge(As,K,C):
    count = 0
    for i in range(len(As)):
        if As[i]%C == 0:
            m = As[i]//C - 1
        else:
            m = As[i]//C
        count += m
    if count <= K:
        return True
    else:
        return False

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

l = 0
r = max(As)
while(r-l>1):
    mid = (l+r)//2
    if judge(As,K,mid):
        r = mid -1
    else:
        l = mid + 1
if judge(As,K,r):
    print(r)
else:
    print(r+1)

Submission status: Accepted

Solution code:
from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
def chk(L):
    cnt = 0
    for i in range(N):
        cnt += ceil(A[i]/L)-1
    return cnt <= K
l, r = 1, max(A)
while l <= r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
print(min([x for x in [m-1,m,m+1] if x > 0 and chk(x)]))

Submission status: Accepted

Solution code:
def is_ok(x):
    cnt = 0
    for a in A:
        cnt += -(-a//x)-1
    if cnt <= k:
        return True
    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
    
n, k = map(int,input().split())
A = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
import sys

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

l, r = 0, max(a)
while r - l > 1:
  # satisfy l < t < r
  t = (l + r) // 2
  c = sum([(e-1) // t for e in a])
  if k < c:
    l = t
  else:
    r = t
print(r)

Submission status: Accepted

Solution code:
import sys , math

N,K=list(map(int, input().split()))
Ws=list(map(int, input().split()))
Ws.sort(reverse=True)

l=0
r=10**9

def check (m):
    now=0
    for i in range(N):
        now += (Ws[i] - 1) // m
    return now <= K

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

    if check(m):
        r = m
    else:
        l = m
print(r)

Submission status: Accepted

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

Max = max(log_ls)

def less_k(min_length,log_ls = log_ls,K=K):
    times = 0
    for log in log_ls:
        if log % min_length == 0:
            times += log // min_length -1
        else:
            times += log // min_length
    if times <= K:
        return True
    else:
        return False
#print(less_k(5,[10,10],2))

def return_min_length():
    r = Max
    l = -1
    while True:
        next_length = (r+l) // 2
        if next_length == 0 or not less_k(next_length):
            l = next_length
        else:
            r = next_length
        if r - l == 1:
            return r

ans = return_min_length()
print(ans)

Submission status: Accepted

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

    def value(v):
        cnt = 0
        for i in a:
            cnt += (i-1)//v
        if cnt > k:
            return False
        else:
            return True

    def b_search(ok, ng, value):
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if value(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(b_search(10**16, 0, value))


main()

Submission status: Accepted

Solution code:
from  heapq import heappush, heappop, heapify
import math

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

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

l = 0
r = 10 ** 9

def check(m):
    now = 0
    for i in range(N):
        #A[i]-1してるのは、たとえばm=3のときは4,7から回数が増えるため
        now += (A[i]-1) // m
    return now <= K

#差が1になったら終了
while r - l > 1:
    m = (l + r) // 2

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

print(r)

Submission status: Accepted

Solution code:
def possible(x):
    global k
    cnt = 0
    for i in a:
        if i % x == 0:
            cnt += i // x - 1
        else:
            cnt += i // x

    if cnt <= k:
        return True
    return False

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

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

mini = 1
maxi = max(a)

while mini <= maxi:
    mid = (mini + maxi) // 2
    res = possible(mid)
    if res:
        maxi = mid
    else:
        mini = mid
    # print(mini, mid, maxi)

    if mini+1 >= maxi:
        if maxi < mini:
            mini, maxi = maxi, mini
        if possible(mini):
            ans = mini
        else:
            ans = maxi
        break

print(ans)
# print(possible(4))

Submission status: Accepted

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

def judge(ans,K,A):
    cut=0
    for i in range(len(A)):
        cut+=(A[i]-1)//ans
    if cut>K:
        return False
    else:
        return True


ansp=max(A)
ansm=0
ans=(ansp+ansm)//2
d=1
while ansp-ansm>d:
    
    if judge(ans,K,A):
        ansp=ans
        
    else:
        ansm=ans
        
    ans=(ansp+ansm)//2
print(ansp)

Submission status: Accepted

Solution code:
from math import ceil


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

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

OK, NG = 10**9, 0
while OK - NG > 1:
    mid = (OK + NG) // 2
    if f(mid):
        OK = mid
    else:
        NG = mid

print(OK)

Submission status: Accepted

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

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

left = 0
right = max(Alist)

while right - left > 1:
    mid = (left + right) // 2
    
    cnt = 0
    for A in Alist:
        if A % mid == 0:
            cnt += (A // mid) - 1
        else:
            cnt += (A // mid)
    
    if cnt <= K:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

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

# xは求める長さ
def C(x):
    num = 0
    for i in range(n):
        # (a[i]-1)//x 回切る必要がある
        num += (l[i]-1)//x
    # k回以内に収まるか
    return num <= k

lb,ub = 0,max(l)
while ub-lb > 1:
    mid = (lb + ub) // 2
    # 条件を満たすならxを小さくしていく
    if C(mid):
        ub = mid
    else:
        lb = mid
    # print(lb,ub)

print(ub)

Submission status: Accepted

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

# xは求める長さ
def C(x):
    num = 0
    for i in range(n):
        # (a[i]-1)//x 回切る必要がある
        num += (l[i]-1)//x
    # k回以内に収まるか
    return num <= k

lb,ub = 0,max(l)
while ub-lb > 1:
    mid = (lb + ub + 1) // 2
    # 条件を満たすならxを小さくしていく
    if C(mid):
        ub = mid
    else:
        lb = mid
    # print(lb,ub)

print(ub)

Submission status: Accepted

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

# xは求める長さ
def C(x):
    num = 0
    for i in range(n):
        # (a[i]-1)//x 回切る必要がある
        num += (l[i]-1)//x
    # k回以内に収まるか
    return num <= k

lb,ub = 0,max(l)
for i in range(100):
    mid = (lb + ub) / 2
    # 条件を満たすならxを小さくしていく
    if C(mid):
        ub = mid
    else:
        lb = mid
    # print(lb,ub)

import math
ans = math.ceil(ub)
print(ans)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
U = max(A)+1
L = 0


def can(x, K):
    ct = 0
    for i in range(N):
        ct += (A[i]-1)//x
    if ct <= K:
        return True
    else:
        return False


while U-L > 1:
    x = (U+L+1)//2
    if can(x, K):
        U = x
    else:
        L = x

print(U)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys
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()))


class Logs():
    def __init__(self, K, logs):
        self.K = K
        self.logs = logs

    def canCutUnderX(self, X):
        times = 0
        for log in self.logs:
            time = math.floor(log/X)
            if log % X == 0:
                time -= 1
            times += time
            if times > self.K:
                return False

        return True

    def solve(self):
        ans = self.nibutan(0, max(self.logs))
        return ans

    def nibutan(self, l, r):
        if l + 1 == r:
            return r
        c = (l + r) // 2

        if self.canCutUnderX(c):
            return self.nibutan(l, c)
        else:
            return self.nibutan(c, r)


def main():
    _, K = MI()
    logs = LI()

    solver = Logs(K, logs)
    print(solver.solve())


main()

Submission status: Accepted

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

s = (10**9) // 2
step = s
best= 999999999999
import math

for j in range(50):
  c = 0
  arr = list(f)

  for i in range(n):
    if arr[i] > s:
      v = 0
      if arr[i] % s != 0:
        c += arr[i] // s
        v += arr[i] // s
      else:
        c += arr[i] // s
        v += arr[i] // s
        c -= 1
        v -= 1
      cor = 0
      if arr[i] % (v+1) != 0:
        cor = 1
      arr[i] = arr[i]//(v+1) + cor
    
  step = step//2
  step = max(1, step)
 
  if c<=k:
    best = min(best,max(arr))
   # print(s,best)
    s -= step
  else:
    s += step
    
  if s==0:
    s=1
      
print(best)

Submission status: Accepted

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

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 + x - 1) // x - 1
    return cnt <= K

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

Submission status: Accepted

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

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

print(meguru_bisect(0,max(A)+1))

Submission status: Accepted

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

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

print(meguru_bisect(0,max(A)+1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, K = NMI()
    A = NLI()
    
    ng = 0       #ng:とり得る最小の値-1
    ok = 10**9+10  #ok:とり得る最大の値+1

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

        cut = 0
        for a in A:
            if a % mid == 0:
                cut += math.floor(a/mid)-1
            else:
                cut += math.floor(a/mid)


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

    print(ok)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)
# 切り上げ割り算
# -(-4 // 3)
# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, K = zz()
A = zz()
max_a = max(A)
rest = K
# 答えはX以下か？を考える
# 長さaの丸太を切ってX以下にするためには、
# -(-a//X)回切る必要がある


def trial(x):
    # print('try', x)
    num_cut = 0
    for a in A:
        num_cut += (-(-a//x)-1)
        # print('num_cut', num_cut)
        if (num_cut > K):
            return False
    return True


# 答えの範囲は0~max(A)
l = 0
r = max_a
while (r - l > 1):
    ans = (l + r) // 2
    if (trial(ans)):
        # print(ans)
        r = ans
    else:
        l = ans
print(r)

Submission status: Accepted

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

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

l = 0; r = 10**10
while r-l > 1:
    x = (l+r)//2
    if f(x):
        r = x
    else:
        l = x
print(r)

Submission status: Accepted

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

def f(x):
    if x!= 0:
        now = 0
        for i in range(N):
            now += (A[i]-1)//x
        return now <= K
    else:
        return False
l = 0; r = 10**10
while r-l > 1:
    x = (l+r)//2
    if f(x):
        r = x
    else:
        l = x
print(r)

Submission status: Accepted

Solution code:
def check(x, A, K):
    import math
    sumA = 0
    for a in A:
        if a > x:
            sumA += math.ceil(a / x) - 1
    if sumA <= K:
        return True
    else:
        return False


def resolve():
    _, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ok = max(A)  # maxVal when minimize
    ng = -1  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid > 0 and check(mid, A, K):
            ok = mid
        else:
            ng = mid
    print(ok)


resolve()

Submission status: Accepted

Solution code:
import base64

exec(base64.b85decode(b'X>D+Ca&#bbbz*RGZ)0V1a|&r~aBp&SAai+h3JPOyWMv>dAaWuiA|q*TV{CO~Wgt9ZY-ewBX>@39J_;jgZewh9WMv>cVrg`9Wpq9YBWZ49Y;|O1AUtDXb8}^KbUq3rX>Ma|b!25AJY!>Yd2nSu3L|N5V{CO~Wgt9bXmW3EZ$1hmX>Ma|b!25AJY#KPbZ9;bBWZ49Y;|O1AUtDlZE$R5cs>dvX>Ma|b!25AJY#coa%pa7J_;jgZewh9WMv>cWMy%6Wj+ccX>Ma|b!25AJZW!jVQy(~J_;jgZewh9WMv>cX>W6Ma%Ev{J_;jgZewh9WMv>cZDDXe3L|N5V{CO~Wgt9mb!}yGX=6SLBWZ49Y;|O1AUtt(Wp!mf3L|N5V{CO~Wgt9qVQyq^Z9WPkX>Ma|b!25AJac7qJ_;jgZewh9WMv>cb97;2Yd#7iX>Ma|b!25AJacq%X>Mme3L|N5V{CO~Wgt9sb#QEDJ_;jgZewh9WMv>cb#!TLX>@r$3L|N5V{CO~Wgt9uWn*-2ay|+Qb#rNMXCQ82ZDn(CVPj<=b97`o3JP^|X>Mm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}pZge&@AZt4yV`*+6K0Y9BAU-}IYdZ=cAa-SAbZ>GzX>N2rAYmwODLWuzX>K4sJ|JN`3JM?~X=WfOYal&6ATTK)dkP>RARuFJb#x#+JRmA<VR&C<Y-Md_ZgePNY-}iDDJdX4JRoImWNbSia%FUNa&90nI|?8meF_R7AZc!NAZTf4XdpcxC~0nVDKTX^AS)m-EFf%ecOX3=FgpqgARu>WX>4U6C}?SCXdo>hY;SiUJ|HnEAbScRARr)VZge1RX=EThASh^QXJ{ZRAZ%}UDIh*RATc`%ARr(hX>N2jG$3weWn>^dATT=$ARr(hW^ZyJC~0nVAY~vrAYmyWZe?X;AS*o}C~0nVHZ&<HC}kikAZ=-6AT1y<DIhN(ZE0j6Eg&%|I|>RQARr)VW*{hTWo2X_J|Jr;AbScRARr(hAZ%}UAUz;$X=FPJARr(heIR9Qb7dfV3LqdLARr)UX=i94Js@pqWIGBVARr)p3LqeT3JM?~V{dhIAUr%EXlZ9?AUr%EWo~3_I|>RQAaZ4Nb#iVXFgpr;3L+vR3JP~=bZ8)NaAj^NCv$IXE@N<TCoCW*cPA+zVRIm6Itm~lARuNgcXDZTWhi5BWMwG|3UhU0aB^>BWpi^bP;YQ$ZYWzPXDcfwEFdQ>b97`qV=F5$HzzD0CoNAhCoCW*EpTaYWhX2kCv$IXE@N<TCtWEnV{dJ3b#7^6VRU6EDGGCSVsLVAV`X!5E>Lf9Wo{^2CoV5xE^l>oCtWNcb97{BZas5(b1rjqWNB_JAaitNZ*_D%b9r+vb97{Hb#y5%V{dJ3b#7^6VRU6EDF'))

Submission status: Accepted

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

def f(t):
    return sum(i//t if i!=t else 0 for i in A)<=K if t else all(i<=t for i in A)

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

print(r)

Submission status: Accepted

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

def f(t):
    if t!=0:
        c = 0
        for i in A:
            c += i//t if i!=t else 0
        return c<=K
    else:
        return all(i<=t for i in A)

left, right = -1, 10**10
while right-left>1:
    m = (right+left)//2
    if f(m):
        right = m
    else:
        left = m

print(right)

Submission status: Accepted

Solution code:
import base64

exec(base64.b64decode(b'aW1wb3J0IHN1YnByb2Nlc3MKaW1wb3J0IHN5cwoKY29kZSA9IHIiIiIjaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNjdHlwZT4KI2luY2x1ZGUgPGNocm9ubz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y29tcGxleD4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHJhbmRvbT4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnVzaW5nIGludDY0ID0gbG9uZyBsb25nOwoKI2RlZmluZSBhbGwoXykgYmVnaW4oXyksIGVuZChfKQojZGVmaW5lIHJhbGwoXykgcmJlZ2luKF8pLCByZW5kKF8pCgp0ZW1wbGF0ZSA8Y2xhc3MgVD4KaW5saW5lIHZvaWQgZXJhcXVlKHN0ZDo6dmVjdG9yPFQ+JiB2ZWMpIHsKICB2ZWMuZXJhc2Uoc3RkOjp1bmlxdWUodmVjLmJlZ2luKCksIHZlYy5lbmQoKSksIHZlYy5lbmQoKSk7CiAgcmV0dXJuOwp9Cgp0ZW1wbGF0ZSA8Y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ggLSBsb3cgPiAxKSB7CiAgICBpbnQgbWlkID0gKGhpZ2ggKyBsb3cpID4+IDE7CiAgICBpbnQ2NCBuZWVkID0gMDsKICAgIGZvciAoaW50IGUgOiBhKSBuZWVkICs9IChpbnQ2NCkoKGUgKyBtaWQgLSAxKSAvIG1pZCAtIDEpOwoKICAgIGlmIChuZWVkID4gaykgewogICAgICBsb3cgPSBtaWQ7CiAgICB9IGVsc2UgewogICAgICBoaWdoID0gbWlkOwogICAgfQogIH0KCiAgY291dCA8PCBoaWdoIDw8IGVuZGw7CgogIHJldHVybiAwOwp9CiIiIgoKd2l0aCBvcGVuKCdzb2wuY3BwJywgJ3cnKSBhcyBmOgogICAgZi53cml0ZShjb2RlKQoKc3VicHJvY2Vzcy5Qb3BlbihbJ2crKycsICctc3RkPWMrKzE3JywgJy1PMicsICdzb2wuY3BwJ10pLmNvbW11bmljYXRlKCkKc3VicHJvY2Vzcy5Qb3BlbihbJy4vYS5vdXQnXSwgc3RkaW49c3lzLnN0ZGluLCBzdGRvdXQ9c3lzLnN0ZG91dCkuY29tbXVuaWNhdGUoKQ=='))

Submission status: Accepted

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

    left = 0
    right = 10 ** 9
    while right - left > 1:
        mid = (right+left) // 2
        cnt = 0
        for a in A:
            cnt += (a-1) // mid
        
        if cnt <= K:
            right = mid
        else:
            left = mid

    print(right)
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from math import ceil
def solve():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))

    left = 0
    right = 10 ** 9
    while (right - left) > 1:
        x = (left+right) // 2
        cnt = 0
        for a in A:
            cnt += (a-1) // x
        
        if cnt <= K:
            right = x
        else:
            left = x
    
    print(right)
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
a = readInts()

a.sort(reverse=True)

if n==1:
	print(math.ceil(a[0]/(k+1)))
	exit()

def get(left, right):
	l = (right-left)//2+left
	ans = 0
	for i in a:
		ans+=math.ceil(i/l)-1
	#print(l, ans, left, right)
	return ans,l

def nibu(left,right):
	ans,l = get(left, right)

	if left<right:
		if ans<=k:
			return nibu(left,l)
		else:
			return nibu(l+1, right)
	else:
		return right


print(nibu(1,a[0]))

Submission status: Accepted

Solution code:
# Binary Search

def isOK(i, key):
    '''
    問題に応じて返り値を設定
    '''
    cnt = 0
    for v in a:
        cnt += (v + i - 1) // i - 1

    return cnt <= key


def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    O(logN)
    '''
    ok = 10 ** 9  # 条件を満たすindexの上限値/下限値
    ng = 0        # 条件を満たさないindexの下限値-1/上限値+1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if isOK(mid, key):  # midが条件を満たすか否か
            ok = mid
        else:
            ng = mid
    
    return ok


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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from decimal import Decimal, ROUND_HALF_UP


def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))
 
 
    def check(length :int) -> bool:
        cnt = 0
 
        for a in A_list:
            if a >= length:
                divide = math.ceil(a / length)
                cnt += (divide - 1)
        
        return (True if cnt <= K else False)
 
 
    L = 0.1          # the minimum length
    R = max(A_list)  # the maximum length
 
    while (R - L) > 0.01:
        M = L + (R - L) / 2
 
        if check(M):
            R = M
        else:
            L = M
    
    
    ans = Decimal(str(M)).quantize(Decimal('1E-1'), rounding=ROUND_HALF_UP)
    ans = math.ceil(ans)

    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math


def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))


    def check(length :int) -> bool:
        cnt = 0

        for a in A_list:
            if a >= length:
                divide = math.ceil(a / length)
                cnt += (divide - 1)
        
        return (True if cnt <= K else False)


    L = 0            # the minimum length
    R = max(A_list)  # the maximum length

    while (R - L) > 1:
        M = L + (R - L) // 2

        if check(M):
            R = M
        else:
            L = M


    print(R)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math


def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))


    def check(length :int) -> bool:
        cnt = 0

        for a in A_list:
            if a >= length:
                quotient = a / length
                #divide = -(-quotient // 1)  # round up
                divide = math.ceil(quotient)  # round up
                cnt += (divide - 1)
        
        return (True if cnt <= K else False)


    L = 0            # the minimum length
    R = max(A_list)  # the maximum length

    while (R - L) > 1:
        M = L + (R - L) // 2

        if check(M):
            R = M
        else:
            L = M


    print(R)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from decimal import Decimal, ROUND_HALF_UP


def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))


    def check(length :int) -> bool:
        cnt = 0

        for a in A_list:
            if a >= length:
                quotient = a / length
                divide = -(-quotient // 1)  # round up
                cnt += (divide - 1)
        
        return (True if cnt <= K else False)


    L = 0            # the minimum length
    R = max(A_list)  # the maximum length

    while (R - L) > 1:
        M = L + (R - L) // 2

        if check(M):
            R = M
        else:
            L = M


    print(R)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def k_cut_less_than(k, l, woods):
    kaisuu = 0
    for wood in woods:
        kaisuu += (wood-1) // l
    if kaisuu <= k:
        return False
    return True


# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math


def binary_research(start, end,  function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(k, middle, woods):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)

start=0
end=10**9
print(binary_research(start,end,k_cut_less_than)+1)