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:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def f(n,a,c,K):
    now = 0
    for i in range(n):
        now += math.ceil(a[i]/c)-1
    return now <= K

def main():
    N,K = [int(x) for x in stdin.readline().rstrip().split()]
    A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    l,r = 0,int(1e9)
    while r-l > 1:
        c = (l+r)//2
        # print(c,f(N,A,c,K))
        if f(N,A,c,K):
            r = c
        else:
            l = c
            
    print(r)
main()

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
low, high = 0, max(arr) + 1
while high - low > 1:
  mid = (high + low) // 2
  curr = 0
  for i in arr:
    curr += (i - 1)//mid
  if curr > k:
    low = mid
  else:
    high =  mid
print(high)

Submission status: Accepted

Solution code:

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

l=0
r=10**9

def check(x):
    now = 0
    for i in range(n):
        now += (a[i] - 1 )// x
    return now <= k

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

print(r)

Submission status: Accepted

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

def is_ok(arg):
  cnt=0
  for i in a:
    cnt+=(i-1)//arg
  return k>=cnt
  
def binsearch(ng,ok):
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if is_ok(mid):
      ok=mid
    else:
      ng=mid
      
  return ok

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

Submission status: Accepted

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

def f(n):
    cnt = 0
    for a in a_i:
        cnt += (a - 1) // n
    if cnt > k: return False
    else: return True

l, r = 0, max(a_i)
while True:
    if r - l <= 1: break
    val = (l + r) // 2
    if f(val) == True: r = val
    else: l = val
print(r)

Submission status: Accepted

Solution code:
import math as m

def isltK(K,X):
    ccut=0
    for Ai in As:
        ccut += m.ceil(Ai/X)-1
    if ccut <=K:
        return True
    else:
        return False


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

l=1
h=max(As)
while l < h:
    mid = (l+h)//2
    if isltK(K,mid):
        h=mid
    else:
        l=mid+1
print(l)

Submission status: Accepted

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

l, r = 1, 10 ** 9
while l < r:
    m = (l + r) // 2
    if sum(map(lambda v: (v - 1) // m, a)) > k:
        l = m + 1
    else:
        r = m
print(l)

Submission status: Accepted

Solution code:
# にぶたん練習
n,k=map(int,input().split())
a=list(map(int,input().split()))

# カット後のaの最大長を取り、カット数を計算する
# k以下でカット可能ならばTrueを返す。
# にぶたんは、効率良くT/Fを判定できる関数が作れるかがみそ。
def f(n):
  cnt=0
  for aa in a:
    cuta=(aa-1)//n # (ceil(aa/n))と同値？良くわからない。
    cnt+=cuta
  if cnt>k:
    return False
  return True

# にぶたん実装
l,r=0,max(a)
while r-l>1:
  m=(r+l)//2
  if f(m):
    r=m
  else:
    l=m

# 今回は、rが必要な値。厳密な値は(l<x<=r)になるので、小数点切り上げでrとなる。
print(r)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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


def ok(X):
    cnt = 0
    for a in A:
        cnt += (a - 1) // X

    return cnt <= K


def solve():
    l, r = 0, 1000000000

    while l + 1 < r:
        c = (l + r) // 2
        if ok(c):
            r = c
        else:
            l = c

    return r


print(solve())

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

def ok(s):
    c=0
    for i in a:
        c+=-(-i//s)-1
    return c<=k


l=0
r=max(a)
while r>l+1:
    md=(r+l)//2
    if ok(md):
        r=md
    else:
        l=md
print(r)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

# 答えがXであると仮定する
# A_iの丸太をXにするためには、A_i / Xを切り上げた数 - 1回切る必要がある
# 15 を 4にするためには、15 / 4 = 3.x -> 3回切る
# 12 を 4にするためには、12 / 4 = 3 -> 2回切る
# (A_i + X - 1 // X) - 1 回でOK
# ((15 + 4 - 1) // 4) - 1 = 3
# ((12 + 4 - 1) // 4) - 1 = 2
# ((4 + 4 - 1) // 4) - 1 = 0
# Xの値を二分探索。切る回数の合計がK以下ならOK

ok = max(A)
ng = 0

def isOk(x):
  cut = 0
  for a in A:
    cut += ((a + x - 1) // x) - 1
  return cut <= K
  
while abs(ok - ng) > 1:
  mid = abs(ok + ng) // 2
  if isOk(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 = 1
r = max(A)
while l != r:
    mid = (r + l) // 2
    count = 0
    for log in A:
        count += (log - 1) // mid
    if count <= K:
        r = mid
    else:
        l = mid + 1

print(r)

Submission status: Accepted

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

while l + 1 < r:
    m, cnt = (r + l) // 2, 0

    for a in list_A:
        cnt += (a-1)//m

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

print(r)

Submission status: Accepted

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

l = 0
r = max(A)
for _ in range(30):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)

Submission status: Accepted

Solution code:
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


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

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    # print(d, d_max, d_min)

print(d_max)

Submission status: Accepted

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

def can_cut(n):
    tmp = 0
    for a in A:
        tmp += ((a + n - 1) // n) - 1
    if tmp <= K:
        return True
    else:
        return False

l = 0
r = max(A) + 1
while l+1 < r:
    m = (l + r) // 2
    if can_cut(m):
        r = m
    else:
        l = m
print(r)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

def isOK(minVal):
	tmpK=0
	for a in A:
		# math.ceil(a//minVal)-1
		tmpK+=((-(-a//minVal))-1)

	if tmpK <= K:
		return True
	else:
		return False

ok = max(A)
ng = 0

while (math.ceil(ok) != math.ceil(ng)):
	mid = (ok+ng) / 2
	if isOK(mid):
		ok = mid
	else:
		ng = mid
	#print(ok,ng)

print(math.ceil(ok))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
tmax=max(a)
tmin=0
import math
ans=tmax
if k==0:
  print(tmax)
else:
  while True:
    t=(tmax+tmin)//2
    if abs(tmax-tmin)<=1:
      break
    s=0
    for i in range(n):
      s=s+math.ceil(a[i]/t)-1
    if k>=s:
      ans=min(math.ceil(t),ans)
      tmax=t
    else:
      tmin=t
  print(ans)

Submission status: Accepted

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

b = 0
e = max(A)
L = e // 2
while e - b > 1:
    L = (e + b) // 2
    m = sum(list(map(lambda x: (x - 1) // L, A)))
    if m <= k:
        e = L
    else:
        b = L
print(e)

Submission status: Accepted

Solution code:
from math import ceil
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = max(a)
def f(ln, x):
    return ceil(ln/x)-1
while r-l > 1:
    m = (r+l)//2
    cnt = 0
    for i in range(n):
        cnt += f(a[i],m)
    if cnt > k:
        l = m
    else:
        r = m
print(r)

Submission status: Accepted

Solution code:
import math
def judge(x):
    cnt=0
    for l in a:
        c=l//x
        if l%x!=0:
            c+=1
        cnt+=c-1 
    return cnt<=k

n,k=map(int,input().split())
a=list(map(int,input().split()))
left=0
right=max(a)
mid=(left+right)//2
while right-left>1:# 最後は整数なので実数で扱わなくていい
    if judge(mid):
        right=mid
        mid=(left+right)//2
    else:
        left=mid
        mid=(left+right)//2
print(right)

Submission status: Accepted

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

def is_ok(X):
    # 全部をX以下にするために切る回数 <= K
    cnt = 0
    for i in range(N):
        cnt += (A[i]-1)//X
    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))

Submission status: Accepted

Solution code:
"""
AtCoder :: Beginner Contest 174 :: Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
"""
import sys
from math import ceil


def main():
    """Main program."""
    log_count, cut_count = (int(i) for i in sys.stdin.readline().split())
    logs = [int(i) for i in sys.stdin.readline().split()]
    high = max(logs)
    low = 1
    soln = high
    # Binary search for the answer.
    while low <= high:
        mid = (low + high) // 2
        cuts_needed = sum([int(ceil(log / mid)) - 1 for log in logs])
        if cuts_needed <= cut_count:
            soln = min(soln, mid)
            high = mid - 1
        else:
            low = mid + 1
    print(soln)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=0,10**9
f=0
while r-l>1:
    m=(l+r)//2
    count=0
    for i in a:
        count+=math.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=[int(x) for x in input().split()]

s,l=0,max(A)
while l-s>1:
  m=(s+l)//2
  if sum([(a-1)//m for a in A]) >k:
    s=m
  else:
    l=m

print(l)

Submission status: Accepted

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

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

ok = max(a)
ng = 0
while abs(ok-ng)>1:
  mid = (ok+ng)//2
  if check(a, mid, k):
    ok = mid
  else:
    ng = mid

print(ok)

Submission status: Accepted

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    import math
    def isok(n):
        ndiv = 0
        for a in A:
            if a <= n:
                continue
            ndiv += math.ceil(a/n)-1
        return True if ndiv <= K else False 
    left = 0
    right = 10**9+1
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if isok(mid):
            right = mid
        else:
            left = mid
    print(math.ceil(right))


if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

def ok(arg):
  cnt = 0
  for log in a:
    cnt += -(-log//arg)
    cnt -= 1
  return cnt<=k

st,en = 0,max(a)
mid = 0
while en-st>1:
  mid = (en+st)//2
  if ok(mid):
    en = mid
  else:
    st = mid

print(en)

Submission status: Accepted

Solution code:
import sys

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

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

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Submission status: Accepted

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

left = 1
right= max(A)

import math

while True:
  
  cl = 0
  for i in range(N):
    cl += math.ceil(A[i]/left) - 1
  
  mid = (left + right)//2
  cm = 0
  for i in range(N):
    cm += math.ceil(A[i]/mid) - 1
  if(cl<=K):
    right = left
    break
  if(cm<=K):
    right = mid
  else:
    left = mid
  if(abs(left-right)<=1):
    break

print(right)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
aas = list(map(int, input().split()))
diff = pow(10,-6)
left = 1
right = 10**9
def judge(mid):
    cut = 0
    for i in aas:
        cut += math.ceil(i / mid) - 1
    if cut <= k:
        return True
    else:
        return False
while left < right:
    mid = (left + right) / 2
    if (left <= right <= left + diff) or (right <= left <= right + diff):
        break
    elif judge(mid):
        right = mid
    else:
        left = mid
print(math.ceil(left))

Submission status: Accepted

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

left = 1
right= max(A)

import math

dict_X = {}
while True:
  
  cl = 0
  for i in range(N):
    cl += math.ceil(A[i]/left) - 1
  cr = 0
  for i in range(N):
    cr += math.ceil(A[i]/right) - 1
  
  mid = (left + right)//2
  cm = 0
  for i in range(N):
    cm += math.ceil(A[i]/mid) - 1
  if(cl<=K):
    right = left
    break
  elif(cm<=K):
    right = mid
  else:
    left = mid
  
  if(left>=right-1):
    break
    
print(right)

Submission status: Accepted

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

MIN=0
MAX=10**9
while MAX-MIN>1:
    mid=(MAX+MIN)//2
    tmp=0
    for i in range(N):
        tmp+=(A[i]-1)//mid
    if tmp>K:
        MIN=mid
    else:
        MAX=mid
print(MAX)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
import math
def hoge(low, high, A, K):
    cnt = 0
    cut = (low + high) // 2
    for i in A:
        cnt += math.ceil(i / cut) - 1
        if cnt > K:
            return True
    return False
low = 1
high = max(A) + 1
cnt = 0
while True:
    if hoge(low,high,A,K):
        low = (low+high) // 2
    else:
        if high == (low + high) // 2 +1:
            if hoge(low,low,A,K):
                low += 1
        else:
            high = (low + high) // 2 +1
    if high - low == 1:
        break
    if cnt == max(A):
        break
    else:
        cnt += 1
print(low)

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
M = max(A)
m = 1
mid = (M+1)//2
while m<M:
  n = 0
  for a in A:
    n += -(-a//mid)-1
    if n > K:
      m = mid+1
      break
  else:
    M = mid
  mid = (M+m)//2
print(mid)

Submission status: Accepted

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

# https://qiita.com/hamko/items/794a92c456164dcc04ad
def binary_search(a, k):
    ng = 0 # left:絶対に達成不可能なもの
    ok = max(a) # right:絶対に達成可能なもの
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if sum([math.ceil(a[i]/mid)-1 for i in range(n)]) <= k:
            ok = mid
        else:
            ng = mid
    return ok
print(binary_search(a, k))

Submission status: Accepted

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

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

left = 0
right = 10**10

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

print(right)

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 binary_search(a, k):
    ng = 0 # left
    ok = max(a) # right
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if sum([math.ceil(a[i]/mid)-1 for i in range(n)]) <= k:
            ok = mid
        else:
            ng = mid
    return ok

print(binary_search(a, k))

Submission status: Accepted

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

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

        if cnt <= 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:
def binary_search(key):
    '''
    条件を満たす最小のindexを求める
    '''
    right = 10 ** 9 + 1
    left = 0
    while right - left > 1:
        mid = (right + left) // 2

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

        if cnt <= key:
            right = mid
        else:
            left = mid
    
    return right


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

print(binary_search(k))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
def test(d,m,u):
    global ans
    p = 0
    for i in range(n):
        if m < a[i]:
            p += a[i]//m
    if u-d <= 1:
        ans = max(ans,m)
        pass
    elif p > k:
        ans = max(ans,m)
        d = m
        m = -(-(m+u)//2)
        test(d,m,u)
    else:
        u = m
        m = -(-(m+d)//2)
        test(d,m,u)
d = 0
m = 1
u = 10**9+7
test(d,m,u)
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while R-L > 0.001:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
if int(R) - int(L) == 0:
    print(int(R)+1)
else:
    print(int(R))

Submission status: Accepted

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

l = 0
r = 10**9 + 1
ref = 0

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
    if ref <= k:
        ref = 0
        r = now
    else:
        ref = 0
        l = now
print(r)

Submission status: Accepted

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

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
    if ref <= k:
        ans = now
        ref = 0
        r = now
    else:
        ref = 0
        l = now
print(ans)

Submission status: Accepted

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

l = 0
r = 10**9 + 1
ref = 0
ans = 10**9

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = now
        ref = 0
        r = now
print(ans)

Submission status: Accepted

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

hi = 10 ** 9
lo = 0
while hi - lo > 1:
    mid = (hi + lo) // 2

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

    if cnt <= k:
        hi = mid
    else:
        lo = mid

print(hi)

Submission status: Accepted

Solution code:
import math
N,K = map(int, input().split())
A_list = list(map(int, input().split()))
lb = 0
ub = 10**9

for i in range(100):
    middle = (lb + ub)/2
    sumi = -N
    for a in A_list:
        sumi += math.ceil(a/middle)

    if sumi <= K:
        ub = middle
    else:
        lb = middle
print(math.ceil(middle))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]

l = 0
r = a[0] + 1
ref = 0
ans = a[0]

while r - l > 1:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = min(ans, now)
        ref = 0
        r = now
print(ans)

Submission status: Accepted

Solution code:
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum((a-1)//m for a in A): ng = m
    else: ok = m
print(ok)

Submission status: Accepted

Solution code:
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum(map(lambda a: (a-1)//m, A)): ng = m
    else: ok = m
print(ok)

Submission status: Accepted

Solution code:
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum([(a-1)//m for a in A]): ng = m
    else: ok = m
print(ok)

Submission status: Accepted

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

l = 0
r = max(a) + 1
ref = 0
ans = 10**9

while l + 1 < r:
    now = (l + r)//2
    for i in a:
        ref += 0 - -i//now - 1
        if ref > k:
            ref = 0
            l = now
            break
    else:
        ans = min(ans, now)
        ref = 0
        r = now
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()


# def binary_search(low, high):

#     while low <= high:
#         mid = (low + high) // 2
#         guess = list[mid]
#         if guess == item:
#             return guess
#         if guess > item:
#             high = mid - 1
#         else:
#             low = mid + 1
low = 0
high = max(A)

while high != low+1:
    mid = (low + high) // 2
    cut_cnt = 0
    # print(low, high)
    # print(mid)
    for i in range(N):
        tmp = math.ceil(A[i] / mid)
        if tmp > 0:
            cut_cnt += tmp - 1
    if cut_cnt <= K:
        high = mid
    else:
        low = mid 
print(high)









"""
L > t, L - t



7,9

3.5, 3.5, 9

3.5, 3.5, 3, 3, 3

K = 1
7, 4.5, 4.5
K = 2
3.5, 3.5, 4.5, 4.5
K = 3
3.5, 3.5, 3, 3, 3

K = 4
2.3, 2.3, 2.3, 3,3,3

"""

Submission status: Accepted

Solution code:
## coding: UTF-8
import math

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


ok = max(A)
ng = 0
#print(ok, ng)

#print(math.ceil(40 / 10.0) - 1)

def hantei(p):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / p) - 1
        #print(A[i], 'done', cnt)
    #print(p, cnt, K)
    if(cnt > K):
        #ng
        return 'ng'
    else:
        return 'ok'



def shisya(ans):
    if((ans - ans // 1) >= 0.5):
        return(int(ans//1+1))
    else:
        return(int(ans//1))   



while shisya(ok)-shisya(ng) > 1:
    #if(ok - ng < 3.5 - 3.49999999):
        #break
    mid = shisya((ok+ng)/2)
    #print('~~~')    
    #print(ok, ng, mid)
    if(hantei(mid) == 'ng'):
        ng = mid
    else:
        ok = mid
    #print(ok, ng)

#print('ans')
print(shisya(ok))

Submission status: Accepted

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

max_len = max(A)
def f(x):
    ans = 0
    for a in A:
        cut_num = math.ceil(a / x) - 1
        #print(a, cut_num, a / x)
        ans += cut_num
    if ans <= k:
        return True
    else:
        return False

left = 0.001
right = max_len
while right - left > 1:
    mid = (right + left) // 2
    if f(mid):
        right = mid
    else:
        left = mid
else:
    print(int(right))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
import math
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]

def array2d(N, M, initial=0):
    return [[initial]*M for _ in range(N)]

def copy2d(orig, N, M):
    ret = array2d(N, M)
    for i in range(N):
        for j in range(M):
            ret[i][j] = orig[i][j]
    return ret


INF = float("inf")
MOD = 10**9 + 7


def main():
    N, K = MAP()
    A = LI()

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

    # 決め打ち二分探索
    left = 0
    right = 10**9+7
    # for i in range(100):
    while right - left > 1:
        mid = (right + left) // 2
        count = 0
        for a in A:
            count += int(math.ceil(a / mid))-1
        if count <= K:
            right = mid
        else:
            left = mid
    # print(int(math.ceil(left)))
    print(right)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)


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


def main(input, print):
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    l = 0
    r = 10**9
    while(r-l > 1):
        x = (l+r) // 2
        if f(x, N, K, A):
            r = x
        else:
            l = x
    print(r)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = [*map(int, input().split())]
A.sort(reverse=True)
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A:
        d = (a - 1) // m
        if d == 0: break
        c += d
    if c <= k: ok = m
    else: ng = m
print(ok)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = [*map(int, input().split())]
A.sort(reverse=True)
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A:
        d = (a - 1) // m
        if d > 0: c += d
        else: break
    if c <= k: ok = m
    else: ng = m
print(ok)

Submission status: Accepted

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

left = 0
right = max(A)

#if accumulate[(ai-1)//k]<=k return True?
def is_ok(x):
  cnt = 0
  for i in range(n):
    cnt += (A[i]-1)//x 
  return cnt<=k
     
#binary search
while (right-left)>1:
  mid = (left+right)//2
  if is_ok(mid):
    right = mid
  else:
    left = mid
    
print(right)

Submission status: Accepted

Solution code:
def check(x,k,arr):
    now = 0
    for i in range(len(arr)):
        now+=int((arr[i]-1)/x)
    return now<=k

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

r, l = 1e9, 0
while (l+1<r):
    x = int((r+l)/2)
    if check(x,k,arr):
        r = x
    else:
        l = x
print(int(r))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30 # (ng,ok] = (l,r]
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a-1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<32 # (ng,ok] = (l,r]
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a-1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)