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


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//n-1
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

    return now <= k

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

print(ok)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
import numba


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


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

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

        if left_bar > right_bar - 2:
            break
    return right_bar


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


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


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

Submission status: Accepted

Solution code:
import math

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

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

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

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

print(middle)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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


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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import ceil

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

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline

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

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

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

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

Submission status: Accepted

Solution code:
import math

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

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

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

def main():
    n, k = map(int, input().split())
    L = list(map(int, input().split()))
    # k 回以内のカットで作成できる最小の上限サイズを特定する
    left = 0
    right = 10 ** 9    # 必ず k 回以内
    while right - left > 1:
        mid = (left + right) // 2
        if min_cut_num(n, L, mid) <= k:
            right = mid
        else:
            left = mid
    print(right)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

l , r = 0, max(a)

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

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

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

print(r)

Submission status: Accepted

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

    left = 0
    right = max(A)

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

Submission status: Accepted

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

    left = 0
    right = max(A)

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

Submission status: Accepted

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

    left = 0
    right = max(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def is_ok(n):
    cnt = 0
    for a in A:
        if n >= a:
            continue
        cnt += a // n
    return cnt <= K

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

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

Submission status: Accepted

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

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

lower = 0
upper = max(L)

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

print(upper)

Submission status: Accepted

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

l = 0
r = 1000000000

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

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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


ng = 0##ngは常に条件を満たさないように設定
ok = max(logs)##okは常に条件を満たすように設定
while abs(ok-ng)>1:##absをとることで問題ごとにokとngの大小を考えなくてよくなる
  times = 0
  mid = (ok+ng)//2
  for A in logs:
    times += math.ceil(A/mid)-1
    
    
  if times <= K:
    ok = mid##条件を満たすならokを寄せる 
  else:
    ng = mid##満たさないならngを寄せる
    
print(ok)##今回はokそのまま答えだけど普通は添え字

Submission status: Accepted

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

# 丸太がすべてxの長さ以下になる回数を出し、それがＫ回以下か判定する
def f(x):
    now = 0
    for i in range(N):
        now += (A[i]-1)//x
    return now <= K

l = 0
r = 10**9

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
def is_ok(arg):
    tmp=0
    for i in a:
        tmp+=ceil(i/arg)-1
    return tmp<=k


def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
print(meguru_bisect(0, max(a)))

Submission status: Accepted

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


l,r = 0,max(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
#切る回数を足してK以下ならOK
def ok(l):
    x =sum([math.ceil(a/l) -1 for a in A])
    if x <=K:
        return True
   # else:
    #    return False

# 初期入力
import bisect
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = map(int, input().split())
A = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
#E - Logs
import math
# 入力
N,K = map(int,input().split())
A   = list(map(int,input().split()))
Amax = int(max(A))
high = Amax
Cancut = Amax
low  = 0
while ( (high - low) > 0.01 ) :
    Cut = 0
    X = (high + low) / 2.0
    for i in range(N):
        Cut = Cut + math.ceil(A[i]/X) - 1
    if Cut <= K:
        high = X
        Cancut = X
    else:
        low  = X
# 出力
if (math.floor(high) != math.floor(low)):
    Cancut = math.floor( 100 * Cancut) /100.0
print(math.ceil(Cancut))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

    print(binary_search())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

ub = 10 ** 9 + 7
lb = 0
while ub - lb > 1:
    mid = (ub + lb) // 2

    cnt = 0
    for v in X:
        cnt += -(-v // mid) - 1

    if cnt <= K:
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Accepted

Solution code:
import math

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

def binary_search(ng=0, ok=max(a)):
    if ok - ng < 2: return ok
    mid = (ok + ng) // 2
    cnt = 0
    for i in a:
        cnt += math.ceil(i / mid) - 1
    if cnt <= k:
        return binary_search(ng, mid)
    else:
        return binary_search(mid, ok)
print(binary_search())

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
X = max(A)
if K == 0:
    print(X)
    exit()
else:
    for i in range(1, math.ceil(math.log2(X)) + 5):
        B = []
        for a in A:
            b = math.ceil(a / X) - 1
            B.append(b)
        B_total = sum(B)
        if B_total > K:
            X += max(A) / pow(2, i)
        else:
            X -= max(A) / pow(2, i)
    print(math.ceil(X))

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,k = ma()
A = list(ma())
A.sort(reverse=True)
if k==0:
    print(A[0])
    exit()

def isok(x):
    cnt=0
    for a in A:
        cnt+= (a-1)//x
    #print(cnt,x)
    return cnt>k
def bisect():
    ok = 0
    ng = 10**9+1
    x = (ok+ng)//2
    while ng-ok>1:
        if isok(x):
            ok = x
        else:
            ng=x
        x = (ok+ng)//2
    return ng
print(bisect())

Submission status: Accepted

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

left = 0
right = 10**9

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

Submission status: Accepted

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

# binary search
left = 1
right = 10 ** 9

while left < right:
    center = (left + right) // 2

    total = 0
    for i in a:
        if i % center == 0:
            i -= 1
        total += i//center
    
    if total > k:
        left = center + 1
    else:
        right = center

print(left)

Submission status: Accepted

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

def queri(n):
    count = 0
    for i in A:
        count += -(-i//n)-1
    if k>= count:
        return True
    else:
        return False

while ok - ng > 1:
    mid = (ok+ng)//2
    if queri(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()))
left, right = 0, max(A)
while right - left != 1:
    mid = (left + right) // 2
    tmp = 0
    for i in A:
        tmp += i // mid - 1 if i % mid == 0 else i // mid

    if tmp > K:
        left = mid
    else:
        right = mid

print(right)

Submission status: Accepted

Solution code:
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))
def chk(mid,a,n,k):
    cuts=0
    for i in a:
        if i <= mid:
            continue
        cuts += i//mid+(-1 if i%mid==0 else 0)
    return (True if cuts<=k else False)

n,k = rm()
a = rl()
lo = 1
hi = 10**9
ans = 10**9
while lo < hi :
    mid = (lo+hi)//2
    if chk(mid,a,n,k):
        hi=mid
        ans=mid
    else:
        lo = mid+1
print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    A = LI()

    # 最大の長さがxになるような切断回数
    def cut_num(x):
        ret = sum([math.ceil(i / x) - 1 for i in A])
        return ret

    ng = 0
    ok = max(A)
    while abs(ok-ng)>10**(-6):
        m = (ng+ok)/2
        if cut_num(m) <= K:
            ok = m
        else:
            ng = m

    print(math.ceil(ok))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    log_no, cut_max = [int(x) for x in input().split()]
    logs = [int(x) for x in input().split()]
    bin_l, bin_r = 0, 10 ** 9
    while bin_r - bin_l > 1:
        bin_mid = (bin_l + bin_r) // 2
        cut_count = sum((log - 1) // bin_mid for log in logs)
        if cut_count <= cut_max:
            bin_r = bin_mid
        else:
            bin_l = bin_mid
    print(bin_r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while r - l > 1:
    mid = (l + r) // 2
    if cal(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()))

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while abs(r - l) > 1:
    mid = (l + r) // 2
    if cal(mid):
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

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

def solver(x):
    cnt = 0
    for logs in l:
        if logs % x == 0:
            cnt += (logs // x) -1
        else:
            cnt += logs// x
    if cnt <= k:
        return True
    else:
        return False

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

print(ok)

Submission status: Accepted

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

def is_ok(X):
    #最大値をX以下にできるか
    cnt = 0
    for a in A:
        cnt += ceil(a/X)-1
    return cnt <= K

def bisearch(high,low):
    while high - low > 1:
        mid = (high+low)//2
        if is_ok(mid):
            high = mid
        else:
            low = mid
    return high

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

Submission status: Accepted

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

ok=max(alst)
ng=0

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

    cnt=0

    for a in alst:
        cnt+=(a+cen-1)//cen-1

    if cnt<=k:
        ok=cen
    else:
        ng=cen

print(ok)

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split()))
alst=list(map(lambda x:int(x)*100,input().split()))

ok=max(alst)
ng=0

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

    cnt=0

    for a in alst:
        cnt+=(a+cen-1)//cen-1

    if cnt<=k:
        ok=cen
    else:
        ng=cen+1

if ok%100==0:
    print(ok//100)
else:
    print(ok//100+1)

Submission status: Accepted

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


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


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


print(meguru_bisect(0, max(a)))

Submission status: Accepted

Solution code:
from math import floor, ceil

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = 0
r = max(a)
while r - l > 1:
    c = (l+r)//2
    cnt = 0
    for i in a:
        cnt += max(ceil(i/c) - 1, 0)
    if cnt <= k:
        r = c
    else:
        l = c
print(r)

Submission status: Accepted

Solution code:
import math
import sys
sys.setrecursionlimit(10**8)
n, k = map(int, input().split())
a = list(map(int, input().split()))
def binary_search(left, right):
    if right - left <= 0.01:
        return right
    middle = (right + left) / 2
    if is_can(middle):
        return binary_search(left, middle)
    else:
        return binary_search(middle, right)
def is_can(target):
    count = 0
    for i in range(n):
        if a[i] > target:
            count += a[i] // target
    return count <= k
p = binary_search(0, 10**10)
if int(p) != 0 and is_can(int(p)) :
    print(int(p))
else:
    print(int(p) + 1)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    import math

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

    left, right = 1, 10**9
    while left != right:
        mid = (left+right)//2
        cut = 0

        for a in As:
            if a/mid > 1: cut += math.ceil(a/mid) - 1

        if cut <= K:
            # 切って良い回数を満たしている
            if left+1 == right:
                print(left)
                return
            right = mid
        else:
            # 切って良い回数を満たしていない
            if left+1 == right:
                print(right)
                return
            left = mid



if __name__ == "__main__":
    solve()

Submission status: Accepted

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

l = 1
r = 10**9+1

while l < r:
    mid = (l+r)//2
    count = 0
    for i in range(n):
        if A[i] > mid:
            count += A[i]//mid

    if count <= k:
        r = mid
    else:
        l = mid+1


print(l)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc174/tasks/abc174_e

from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))

L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0

while i<100:
    i +=1
    for num in A:
        cnt += ceil(num/ans)-1
    if cnt <=K:
        R = ans
    elif cnt>=K:
        L = ans
    else:
        #print("fin",i-1,cnt,ans)
        break           
    ans = (R+L)/2
    cnt=0
        
print(ceil(ans))

Submission status: Accepted

Solution code:
import math
N, K = map(int,input().rstrip().split())
A = list(map(int,input().rstrip().split()))
maxX = max(A)
minX = 0
X = (maxX + minX)//2

while X!=minX:
    num = sum([math.ceil(A[i]/X)-1 for i in range(N)])
    if num<=K:
        maxX = X
    else:
        minX = X
    X = (maxX + minX)//2
num = sum([math.ceil(A[i]/maxX)-1 for i in range(N)])
if num<=K:
    print(maxX)
else:
    print(minX)

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

print(r)