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:
# -*- 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.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 = float( Decimal(str(M)).quantize(Decimal('1E-1'), rounding=ROUND_HALF_UP) )
    ans = -(-ans // 1)  # round up
    print( int(ans) )


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())
A=list(map(int, input().split()))
l=0
r=max(A)
while not l+1==r:
    x=(r+l)//2
    k=0
    for a in A:
        k+=math.ceil(a/x)-1
    if k<=K:
        r=x
    else:
        l=x
print(r)

Submission status: Accepted

Solution code:
from math import ceil

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

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

left = 0
right = max(A)
while left < right-1:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

Submission status: Accepted

Solution code:
from math import ceil


def check(x):
    # 全てを長さx以下にするために必要な回数
    cnt = 0
    for a in A:
        # 切る回数は-1した回数。a=20 x=4 20/4=5 だが切る箇所は4。
        cnt += ceil(a/x)-1
    return cnt <= K


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

left = 0
right = max(A)
while left < right-1:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

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

low=0
high=10**9+1

while high-low!=1:
    mid=(high+low)//2
    cut_temp=0
    ans=-1
    
    for a in A:
        cut_temp+=-(-a//mid)-1
    if cut_temp>K:
        low=mid
    else:
        high=mid
    
print(high)

Submission status: Accepted

Solution code:
"""ABC174E diff: 1158
"""

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

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

def f(x):
    """
    K回以内のカットで全ての丸太の長さをX以下にできるか？
    X: int
    Return: bool
    """
    cnt = 0
    for a in A:
        if a % x == 0:
            cnt += a//x - 1
        else:
            cnt += a//x
    
    if cnt <= K:
        return True
    else:
        return False

left = 0
right = max(A) + 10

while right - left > 1:
    mid = (left+right) // 2
    if f(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()))

left = 0
right = max(A)

while right - left > 1:
    mid = (left + right) // 2
    jk = 0
    for i in range(N):
        jk += A[i] // mid - 1
        if A[i] % mid != 0: jk += 1
    if jk <= K:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]
left, right = 1, 10**9
while left < right:
    middle = (left + right)//2
    count = sum(i//middle for i in a)
    if count <= k:
        right = middle
    else:
        left = middle + 1
print(left)

Submission status: Accepted

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

left, right = 1, 10**9
while left < right:
    middle = (left + right)//2

    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)

Submission status: Accepted

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

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    if middle==0:
        left=1
        break
    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)

Submission status: Accepted

Solution code:
import math
n,k=map(int, input().split())
a=list(map(int, input().split()))
right=max(a)
left=0
def cutable(a,x):
    count=0
    for i in a:
        count+=math.ceil(i/x)-1
    return count<=k
while right>left+1:
    mid=(right+left)//2
    if cutable(a,mid):
        right=mid
    else:
        left=mid
print(right)

Submission status: Accepted

Solution code:
# E - Logs
import sys
sys.setrecursionlimit(1000000)

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

def rec(l,r):
    global N,K,A
    if l==r:
        return l
    tmp = (l+r)//2
    ans = 0
    for i in range(N):
        ans += (A[i]-0.001)//tmp
    if ans<=K:
        return rec(l,tmp)
    else:
        return rec(tmp+1,r)
    
print(rec(1,max(A)))

Submission status: Accepted

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

def C(x):
  return sum([(A[i]-.5)//x for i in range(N)]) <= K
  
def binary_search2(func, n_min, n_max):
    left,right=n_min,n_max
    while right-left>1:
        middle = (left+right)//2
        y_middle = func(middle)
        if y_middle: right=middle
        else: left=middle

    return right
  
print(binary_search2(C, 0, max(A)+1))

Submission status: Accepted

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

def C(x):
  return sum([(A[i]+x-1)//x-1 for i in range(N)]) <= K
  
def binary_search2(func, n_min, n_max):
    left,right=n_min,n_max
    while right-left>1:
        middle = (left+right)//2
        y_middle = func(middle)
        if y_middle: right=middle
        else: left=middle

    return right
  
print(binary_search2(C, 0, max(A)+1))

Submission status: Accepted

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

def isOK(X):
    if X<=0:
        return False
    return sum([-a//X*-1-1 for a in A])<=K


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

Submission status: Accepted

Solution code:

def fun(X_high, X_low, K, line):
    X = (X_high + X_low) // 2
    cnt = 0
    for tree in line:
        if tree <= X:
            continue
        else:
            q, r = divmod(tree, X)
            if r == 0:
                q -= 1
            cnt += q
    if cnt > K:
        X_low = X
    else:
        X_high = X
    return X_high, X_low

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

X_high = max(line)
X_low = 0

while (X_high - X_low) > 1:
    X_high, X_low = fun(X_high, X_low, K, line)
    
print(X_high)

Submission status: Accepted

Solution code:
import math

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

left = 0
right = max(An)

def check(x):
    chk = 0
    for i in range(n):
        chk += math.ceil(An[i]/x)-1
    return chk

while right-left!=1:
    x = (left+right)//2
    if check(x)<=k:
        right = x
    else:
        left = x

print(right)

Submission status: Accepted

Solution code:
import numpy as np

N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])
I = np.array([1] * N)

L = np.max(A)

ans = L
low = 1
high = L
while 1:
    if low == high:
        ans = low
        break
    
    mid = (low + high) // 2
    if np.sum((A - I) // mid) <= K:
        high = mid
    else:
        low = mid + 1

print(ans)

Submission status: Accepted

Solution code:
# ABC174 E

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

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        if a_l[i] % len == 0:
            ret += a_l[i] // len - 1
        else:
            ret += a_l[i] // len
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

print(right)

Submission status: Accepted

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

def f(length, ls):
    cur = 0
    for a in ls:
        if a%length == 0:
            cur += a//length - 1
        else:
            cur += a//length
    if cur <= K:
        return True
    else:
        return False

ok, ng = max(A), 0
while abs(ok - ng) > 1:
    z = (ok+ng)//2
    if f(z, A) == True:
        ok = z
    else:
        ng = z
print(ok)

Submission status: Accepted

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

l = 0
r = 10**9
while r - l > 1:
    m = (l+r) // 2
    cnt = 0
    for i in a:
        cnt += math.ceil(i / m) - 1
    if cnt <= k:
        r = m
    else:
        l = m
print(l+1)

Submission status: Accepted

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

def check(m):
    n = 0
    for a in A:
        if a%m == 0:
            n += a//m - 1
        else:
            n += a//m
    return n <= K
        

l = 0
r = 10**9+10

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

print(r)

Submission status: Accepted

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


def cut_count(A, m):
    """最長の長さ(切り上げ)がm以下になるような切断回数"""
    total = 0
    for a in A:
        n = (a - 1) // m
        total += n
    return total


def solve(N: int, K: int, A: "List[int]"):
    r = max(A)
    l = 0
    while l + 1 < r:
        m = (r + l) // 2
        if cut_count(A, m) <= K:
            r = m  # r は K回以下の切断回数で到達できる長さ
        else:
            l = m  # l は K回より多いの切断回数で到達できる長さ
    # print(l, r)
    return r


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, K, A)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = np.array(tuple(map(int, args[1].split())))

    l, r = 0, np.max(A)
    while l+1 < r:
        m = (l+r)//2
        if k < np.sum(np.ceil(A/m)-1):
            l = m
        else:
            r = m

    return str(r)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = np.array(tuple(map(int, args[1].split())))

    l, r = 0, np.max(A)
    while l+1 < r:
        m = (l+r)//2
        if k < np.sum(-(-A//m)-1):
            l = m
        else:
            r = m

    return str(r)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
# coding: utf-8

def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = tuple(map(int, args[1].split()))

    l, r = 0, max(A)
    while l+1 < r:
        m = (l+r)//2
        cnt = 0
        for a in A:
            cnt += -(-a//m)-1

        if k < cnt:
            l = m
        else:
            r = m

    return str(r)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
# coding: utf-8

def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = tuple(map(int, args[1].split()))

    l, r = 1, max(A)
    while 0.1 < r-l:
        m = (l+r)/2
        cnt = 0
        for a in A:
            cnt += -int(-a//m)-1

        if k < cnt:
            l = m
        else:
            r = m

    return str(-int(-l//1))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
# 入力
# 値は全てint
# Nは本数、Kは切る回数、AはN本の木のそれぞれの長さ(リスト)
N,K = map(int,input().split())
A = list(map(int,input().split()))

# 二分探索
# lが左端、rが右端
l,r = 0, 10**9

# 整数で返すので、差が１より大きい時はループする
while r - l > 1:
    # 真ん中を設定
    x = (r+l) // 2

    # 切る回数をc
    c = 0
    for a in A:
        # それぞれの丸太の(長さ-1)をxで割った値の合計が、切る回数
        c += (a-1) // x 

    # 切る回数がKよりも小さい時はOKなので右端を寄せる
    if c <= K:
        r = x
    else:
        l = x
    
print(r)

Submission status: Accepted

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

left = 0
right = 10**9

while right - left > 1:
  
  mid = (left + right) // 2
  
  cut = 0
  for i in range(n):
    cut += -(log[i]//-mid)-1

  if cut > k:
    left = mid
  else:
    right = mid
    
print(right)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=10**10
while ok-ng>1:
  m=(ok+ng)//2
  c=0
  for i in a:
    c+=(i//m-(i%m==0))
  if c<=k:
    ok=m
  else:
    ng=m
print(ok)

Submission status: Accepted

Solution code:
import sys



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


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

    ng = 0
    ok = 10 ** 9 + 1

    while ok - ng > 1:
        mid = (ok + ng) // 2
        ans=0
        for i in A:
            a,b =divmod(i,mid)
            ans +=a-1
            if b!=0:
                ans+=1
            if ans >K:
                break

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

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys



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


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

    ng = 0
    ok = 10 ** 9 + 1

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

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

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys



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


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

    ng = 0
    ok = 10 ** 9 + 1
    A.sort(reverse=True)

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

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

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math


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


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

    ng = 0
    ok = 10 ** 9 + 1

    while ok - ng > 1:
        mid = (ok + ng) // 2
        ans = sum(list(map(lambda x: math.ceil(x / mid) - 1, A)))

        # for i in range(N):
        #     ans += A[i]//mid -1
        #     if A[i]%mid !=0:
        #         ans +=1

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

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


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


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


    ng =0
    ok =10**9+1

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

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

    print(ok)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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


min_A = 0
max_A = 10**10

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

print(int(min_A) + 1)

Submission status: Accepted

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

l = 0
r = 10**10

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

Submission status: Accepted

Solution code:
import math

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

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

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

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

    return right

print(binary_search())

Submission status: Accepted

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

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:
    m=(l+r)//2
    t=0
    for x in a:
        if x<=m:
            continue
        t+=(x+m-1)//m-1
    if t<=k:
        r=m
    else:
        l=m
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

l = 0
r = max(A)+1
def cut(l, k):
    # 長さlの丸太を最大とすることができるかどうかを返す
    for a in A:
        if a > l:
            k -= (-(-a//l) - 1)
    return k >= 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

left = 0
right = 10**9

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

low = 0
high = max(a)

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

print(high)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

r = max(As)

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

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

Submission status: Accepted

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

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

bottom, top = 0, max(A)

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

print(top)

Submission status: Accepted

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

r = max(A)
l = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

l = 0
r = max(list)

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

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

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

print(r)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

bottom, top = 0, max(A)

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

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

Submission status: Accepted

Solution code:
import math

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

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

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

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

print(r)

Submission status: Accepted

Solution code:
import math

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

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

while True: # midの長さの丸太に切るとして2分探索
    mid = (L + R) // 2
    cur = 0
    for i in range(N):
        cur += math.ceil(A[i]/mid) - 1 # 切る必要回数
    
    if cur > K: #K回より大きい時は、L=midとして長くする 
        if L == mid:
            break
        L = mid
    else: #K回以下の時は、R=midとして短くする 
        ans = min(ans, mid)
        if R == mid:
            break
        R = mid
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 解説を参考に作成

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
import math
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, As):
    ans = max(As)
    l, r = 1, ans
    for _ in range(30):
        m = (l + r) // 2
        cnt = 0
        for A in As:
            cnt += math.ceil(A / m) - 1
        if cnt <= K:
            ans = min(ans, m)
            r = m - 1
        else:
            l = m + 1
        if l > r:
            break
    print(ans)


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

Submission status: Accepted

Solution code:
# 解説を参考に作成

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
import math
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, As):
    ans = max(As)
    l, r = 1, ans
    for _ in range(30):
        m = (l + r) // 2
        if m <= 0:
            break
        cnt = 0
        for A in As:
            cnt += math.ceil(A / m) - 1
        if cnt <= K:
            ans = min(ans, m)
            r = m - 1
        else:
            l = m + 1
    print(ans)


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

Submission status: Accepted

Solution code:
import sys

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

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

solve()

Submission status: Accepted

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


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


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

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

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