Problem:


Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192



Sample input:
2 3
7 9


Sample output:
4

Submission status: Accepted

Solution code:
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, K = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))
A = np.array(A, dtype=float)


def test(l):
    # l 以下にできますか
    return np.ceil(A / l - 1).sum() <= K


ok = A.max() + 1
ng = 1e-9
while abs(ok - ng) > 1e-2:
    mid = (ok + ng) / 2
    if test(mid):
        ok = mid
    else:
        ng = mid
ans = math.ceil(ng)
print(ans)

Submission status: Accepted

Solution code:
def countcut(A, length):
    ret = 0
    for a in A:
        ret += -(-a//length) - 1
    return ret


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    lo = 1
    hi = int(1e9)
    while lo < hi:
        mid = (lo+hi) // 2
        if countcut(A, mid) <= K:
            hi = mid
        else:
            lo = mid + 1
    print(lo)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

OK=10**9
NG=0

while OK-NG>1:
    mid=(OK+NG)//2

    ANS=0
    for a in A:
        ANS+=(a-0.01)//mid

    if ANS<=K:
        OK=mid
    else:
        NG=mid
print(OK)

Submission status: Accepted

Solution code:
def main():
    N, K = map( int, input().split())
    A = list( map( int, input().split()))
    cnt = 0
    l = 0
    r = 10**9+1
        
    ans = 0
    while r-l > 1:
        m = (l+r)//2
        k = 0
        # print(l,r)
        for a in A:
            k += ((a+m-1)//m)-1
        if k <= K:
            r = m
        else:
            l = m
    print(r)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import *
N,K=map(int,input().split())
A=list(map(int,input().split()))
Q=[]
heapify(Q)
for i in range(N):
  heappush(Q,(-A[i],1))
x=0
if K==0:
  print(max(A))
  exit()
L,R,M=1,max(A),0
while R!=L:
  M=(L+R)//2
  x=0
  for i in range(N):
    x+=(A[i]-1)//M
  if x>K:
    L=max(L+1,M)
  else:
    R=M
print(L)

Submission status: Accepted

Solution code:
import math,sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=10**9+2
while math.ceil(l)<math.floor(r):
  tr=(l+r)/2
  temp=0
  for i in range(n):
    temp+=math.ceil(a[i]/tr)-1
  if temp<=k:
    r=tr
  else:
    l=tr
tr=math.ceil(l)
if tr==0:
  print(1)
  sys.exit()
temp=0
for i in range(n):
  temp+=a[i]//tr
  if a[i]%tr==0:
    temp-=1
if temp<=k:
  print(tr)
else:
  print(tr+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

l, r = 0, 10**9+2

while r-l > 1:
  key = (r+l)//2
  count = 0
  for i in range(n):
    count += (a[i]-1)//key
  if count <= k:
    r = key
  else:
    l = key

print(r)

Submission status: Accepted

Solution code:

def bisect(ng, ok, judge, eps=1):
    while abs(ng-ok) > eps:
        m = (ng+ok)//2
        if judge(m):
            ok = m
        else:
            ng = m
    return ok

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

K += N
def judge(d):
    return sum((a-1)//d+1 for a in A) <= K


for d in range(1,7):
    r = sum((a-1)//d+1 for a in A)

res = bisect(0,max(A),judge)
print(res)

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

Submission status: Accepted

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

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


l = 0
r = 2*10**9

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

Submission status: Accepted

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

# 合計N+Kこになる


l = 0
r = 2 * 10 ** 9 + 10 ** 6
while r - l > 1:
    m = (r + l) // 2
    cnt = 0
    for a in A:
        cnt += (a + m - 1) // m
    if cnt <= N + K:
        r = m
    else:
        l = m

print(r)

Submission status: Accepted

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,k = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    l = 1
    r = 10**9+1
    while l != r:
        mid = l+(r-l)//2
        nm = 0
        for i in a:
            nm += (i-1)//mid
        if nm > k:
            l = mid+1
        else:
            r = mid

    print(r)

    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def f(x):
  r = 0
  for a in A:
    r += (a+x-1)//x-1
  return r

a = 0
b = 2**32
while b>0:
  if f(a+b)>K:
    a += b
  b //= 2
print(a+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

ng = 0
ok = 10**9
while abs(ng-ok)>1:
    i = (ng + ok)//2
    if check(i):
        ok = i
    else:
        ng = i

print(ok)

Submission status: Accepted

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

l, r = 0, 10 ** 9
while r - l > 1:
    x = (l + r) // 2

    cnt = 0
    for i in range(n):
        if a[i] % x == 0:
            cnt += a[i] // x - 1
        else:
            cnt += a[i] // x

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

print(r)

Submission status: Accepted

Solution code:
def binsearch(good, bad, fn):
    while abs(good - bad) > 1:
        m = (good + bad) // 2
        if fn(m):
            good = m
        else:
            bad = m
    return good

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    def fn(t):
        k = 0
        for a in A:
            k += (a - 1) // t
        return k <= K

    return binsearch(10** 9, 0, fn)

print(main())

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

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



def check(x,k):
    #k回切って最短を長さ x 以下にできるならOK 
    v = 0
    for ai in a:
        v += (ai-1)//x
    return v <= k


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

print(ok)

Submission status: Accepted

Solution code:
def check(x):
    ret = 0
    for e in a:
        ret += max((e - 1) // x, 0)

    return ret <= k


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
    if check(m):
        r = m
    else:
        l = m

print(r)

Submission status: Accepted

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
lb, ub = 0, 10**9
while ub - lb > 1:
    m = (lb + ub) // 2
    cnt = 0
    for i in range(N):
        cnt += (A[i] + m - 1) // m - 1
    if cnt <= K:
        ub = m
    else:
        lb = m
print(ub)

Submission status: Accepted

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

if sum(A)-n <= k:
    print(1)
    exit()
elif k == 0:
    print(max(A))
    exit()
top = 10**9
bottom = 1
def ok(x):
    res = 0
    for a in A:
        res += (a-1)//x
    return res <= k
while top - bottom > 1:
    mid = (top + bottom)//2
    if ok(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()))

ok = max(a)
ng = 0
for _ in range(50):
    mid = (ok+ng)//2
    if(mid==0):
        print(1)
        exit()
    cnt = 0
    for ai in a:
        cnt += (ai-1)//mid
    if(cnt <= k):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Accepted

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

while l < r:
    m = (l + r) // 2
    cnt = 0
    for v in a:
        if m == 0:
            cnt += 2 * v
        else:
            cnt += (v + m - 1) // m - 1
    if cnt <= k:
        r = m
    else:
        l = m + 1

print(l)

Submission status: Accepted

Solution code:
import heapq

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
ok = 10**9
ng = 0
while abs(ng-ok) > 1:
    m = (ok+ng)//2
    cou = 0
    for i in a:
        cou += (i+m-1)//m-1
    if cou <= k:
        ok = m
    else:
        ng = m
print(ok)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))

def check(x):
  k = 0
  for i in range(N):
    if a[i] > x:
      k += a[i] // x
  return k <= K

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

Submission status: Accepted

Solution code:
import sys

n, k, *aaa = map(int, sys.stdin.buffer.read().split())
l = 0
r = max(aaa)
while l + 1 < r:
    m = (l + r) // 2

    cut = 0
    for a in aaa:
        cut += (a - 1) // m

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

print(r)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

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

lo = 1
hi = max(A) + 1

def ceildiv(a, b):
	return (a + b - 1) // b

while lo < hi:
	tar = (lo + hi) // 2

	cuts = 0
	for v in A:
		x = ceildiv(v, tar)
		cuts += x - 1
		if cuts > K:
			lo = tar + 1
			break
	else:
		hi = tar

print(lo)

Submission status: Accepted

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

def chk(x):
    s = 0
    for a in A:
        s += (a - 1) // x
    return 1 if s <= K else 0

l, r = 0, 1 << 30
while r - l > 1:
    m = (l + r) // 2
    if chk(m):
        r = m
    else:
        l = m
print(r)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

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

def solve(mid):
    c=0
    for x in A:
        c+=-(-x//mid)-1
    return K>=c

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
import math
l = 0
r = max(a)+1
for _ in range(100):
  m = (l+r)/2
  kn = 0
  for i in a:
    kn += i//m
  if kn > k:
    l = m
  else:
    r = m
print(math.ceil(l))

Submission status: Accepted

Solution code:
def solve(mid):
    cnt = 0
    for i in range(n):
        cnt += (a[i] - 1) // mid
    return cnt <= k


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

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

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
        cur = 0
        for x in a:
            cur += (x - 1) // mid
        if cur > k:
            ng = mid
        else:
            ok = mid
    print(ok)
    return

solve()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k >= sum(a)-n:
	print(1)
else:
	ok, ng = 10**9, 1
	while ok-ng > 1:
		mid = (ok+ng)//2
		if sum((x-1)//mid for x in a) <= k:
			ok = mid
		else:
			ng = mid
	print(ok)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n, k = na()
a = na()

def nu(h, a):
    ret = 0
    for v in a:
        ret += (v-1) // h
    return ret

if sum(a) - n <= k:
    print(1)
else:
    low = 0
    high = 1000000007
    while high - low > 1:
        h = (high+low)//2
        if nu(h, a) <= k:
            high = h
        else:
            low = h
    print(high)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=max(a)
while ng+1!=ok:
  mid=(ng+ok)//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:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n,k = LI()
    a = LI()
    def f(x):
        tmp = 0
        for ai in a:
            tmp += int(ai / x) - (ai % x == 0)
        return tmp <= k
    ok = 10 ** 9
    ng = 0
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if f(mid):
            ok = mid
        else:
            ng = mid
    print(ok)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,k = readInts()
A = readInts()
if n == 2:
    print('---')
    exit()
def is_ok(mid):
    cnt = 0
    for i in range(n):
        cnt += (A[i]-1)//mid
        if cnt > k:
            return False
    return True




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

print(ok)

Submission status: Runtime Error

Solution code:
def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if sum([(i-1)//x for i in a])<=k: r=m;
    else: l=m;
  print(r)

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  main()

Submission status: Runtime Error

Solution code:
from sys import stdin

input = stdin.readline



def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    left = 0
    right = max(a)

    def ok(l):
        s = sum([i // l for i in a])
        return s <= k

    while left < right:
        mid = (left + right) // 2
        if ok(mid):
            right = mid
        else:
            left = mid + 1
    print(left)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def cut(A, k, size) -> bool:
    cnt = 0
    for a in A:
        cnt += a // size
        if a % size == 0:
            cnt -= 1
        if cnt > k:
            return False
    if cnt <= k:
        return True


def main():
    n, k = input_int_list()
    A = input_int_list()

    left = 0
    right = max(A)

    fail = 0
    success = right

    while True:
        mid = (left + right) // 2
        res = cut(A, k, mid)
        if res:
            right = mid - 1
            success = min(mid, success)
        else:
            left = mid + 1
            fail = max(mid, fail)
        if left == right:
            break
    print(success)
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

if K == 0:
    print(max(A))
else:
    low = 0
    high = max(A)
    while high - low > 0.5:
        mid = (low + high) / 2
        times = 0
        for a in A:
            times += math.ceil(a / mid) - 1
        if K >= times:
            high = mid
        else:
            low = mid
        #print(mid)

    ans = int(mid)
    times = 0
    for a in A:
        times += math.ceil(a / ans) - 1
    if times <= K:
        print(ans)
    else:
        print(ans+1)

Submission status: Runtime Error

Solution code:
import math

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

logmin = math.ceil(sum(alist) / (n + k))
logmax = max(alist)


def howmanytimes(tlist, m):
    totalkaisu = 0
    for i in range(len(tlist)):
        x = math.ceil(tlist[i]/m)-1
        totalkaisu += x
    return totalkaisu


def nibun(listansaku):
    import math
    for i in range(math.ceil(math.log2(len(listansaku)))):
        hantei = math.ceil(len(listansaku)/2)
        hanteiti = listansaku[math.ceil(hantei)]
        kaisu = howmanytimes(alist, hanteiti)
        if kaisu > k:
            listansaku = listansaku[hantei+1:]
        elif kaisu < k:
            listansaku = listansaku[:hantei-1]
        elif kaisu == k:
            return hanteiti
    return 0


sirab = list(range(logmin, logmax+1))
ans = nibun(sirab)
print(ans)

Submission status: Runtime Error

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

ans_l = 0
ans_h = A[0]
while ans_l != ans_h:
    ans_m = (ans_l + ans_h) // 2
    tmp_n = 0
    for a in A:
        tmp_n += ((a + ans_m - 1) // ans_m) - 1
    if tmp_n > K:
        ans_l = ans_m + 1
    else:
        ans_h = ans_m

print(ans_l)

Submission status: Runtime Error

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

ans_l = 0
ans_h = A[0]
while ans_l != ans_h:
    ans_m = (ans_l + ans_h) // 2
    tmp_n = 0
    for a in A:
        tmp_n += math.ceil(a / ans_m) - 1
    if tmp_n > K:
        ans_l = ans_m + 1
    else:
        ans_h = ans_m

print(ans_l)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
l = sum(a)//(n+k)
r = a[-1]
while r-l>=1:
  m = (r+l)/2
  if sum([-(-i//m) for i in a]) > n+k:
    l = m
  else:
    r = m
l = -int(-l//1)
r = -int(-r//1)
if sum([-(-i//l) for i in a]) == n+k:
  print(l)
else:
  print(r)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
l = sum(a)//(n+k)-1
r = a[-1]
while r-l>1:
  m = (r+l)/2
  if sum([-(-i//m) for i in a]) > n+k:
    l = m
  else:
    r = m
l = -int(-l//1)
r = -int(-1//1)
if sum([-(-i//r) for i in a]) == n+k:
  print(r)
else:
  print(l)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
l = sum(a)//(n+k)-1
r = a[-1]
while r-l>1:
  m = (r+l)//2
  if sum([-(-i//m) for i in a]) > n+k:
    l = m
  else:
    r = m
if sum([-(-i//r) for i in a]) == n+k:
  print(r)
else:
  print(l)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
def f(a0,k0):
  if k0==0:
    return -int(-a0[-1]//1)
  else:
    ans = a0[-1]
    for i in range(2,k0+2):
      ans = min(ans,f(sorted(a0[:(len(a0)-1)]+[a0[-1]/i]*i),k0-i+1))
    return ans
print(f(a,k))

Submission status: Runtime Error

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

l=-1
r=max(A)+1
while r-l>1:
  m=(l+r)//2
  cut=0
  
  for i in range(n):
    cut+=((A[i]+m-1)//m)-1
  if cut>k:
    l=m
  else:
    r=m
print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import jit
verbose = False

N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())), dtype=np.int64)

ul = np.ceil(np.sum(A)/(K))
ll= np.floor(np.max(A)/(K+1))

EPS = 1 / 10**6

@jit(nopython=True)
def cut(A, c, N):
    return (np.sum(np.ceil(A/c))-N)

c = np.ceil((ul+ll)/2)
mx = np.max(A)
while True:
    if ul-ll == 1:
        break
    nk = cut(A, c, N)
    if verbose:
        print('c:', c, 'nk:', nk, 'ul - ll:', ul, '/', ll)
    prev = c
    if nk  >K: # more cuts than target; larger logs can be made
        ll = c
        c = np.floor(ul + c)/2)
    else: #i.e. nk < K, less cuts than target
        ul = c
        c = np.ceil((c + ll)/2)
        
if cut(A, ll+EPS, N) >= K:
    print(np.min((np.max(A), int(ul))))
else:
    print(int(ll))

Submission status: Runtime Error

Solution code:
def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid - 1
    return res <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(-1, 1_000_000_000, K))

Submission status: Runtime Error

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

def binsearch(minz, maxz):
    if minz >= maxz:
        return minz

    mid = (maxz + minz)//2
    ncut = 0
    for i in range(N):
        thiscut = int((logs[i] + mid - 1)/mid) - 1
        ncut += thiscut
        if ncut > K:
            return binsearch(mid, maxz)

    if ncut < K:
        return binsearch(minz, mid)
    #else ncut == K
    maxx = 0
    for i in range(N):
        thiscut = int((logs[i] + mid - 1)/mid) - 1
        thislen = int((logs[i] + thiscut)/(thiscut+1))
        if maxx < thislen: maxx = thislen
    return maxx

if K > 0:
    ans = binsearch(1, maxL+1)
else:
    ans = maxL
print(ans)

Submission status: Runtime Error

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, K, A):
    lo = -1
    hi = 10**9
    while hi - lo > 1:
        m = (lo + hi) // 2
        if sum((a + m - 1) // m - 1 for a in A) <= K: hi = m
        else: lo = m
    print(hi)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    * A, = map(int, input().split())
    main(N, K, A)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Max = max(log_ls)

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

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

ans = return_min_length()
print(ans)

Submission status: Runtime Error

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

Max = max(log_ls)

def max_less_K(k):
    times = 0
    for log in log_ls:
        times += log // k
    if times <= Cut:
        return True
    else:
        return False

def return_min_ind_whose_value_not_less_than():
    r = Max
    l = -1
    while True:
        next_k = (r+l) // 2
        if max_less_K(next_k):
            r = next_k
        else:
            l = next_k
        if r - l == 1:
            return r

ans = return_min_ind_whose_value_not_less_than()
print(ans)

Submission status: Runtime Error

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

Max = max(log_ls)

def max_less_K(k):
    times = 0
    for log in log_ls:
        times += log // k
    if times <= Cut:
        return True
    else:
        return False

def return_min_ind_whose_value_not_less_than():
    r = Max
    l = 0
    while True:
        next_k = (r+l) // 2
        if max_less_K(next_k):
            r = next_k
        else:
            l = next_k
        if r - l == 1:
            return r

ans = return_min_ind_whose_value_not_less_than()
print(ans)

Submission status: Runtime Error

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

    if cnt <= k:
        return True
    return False

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

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

mini = 0
maxi = max(a)

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

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

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

Submission status: Runtime Error

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

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

for j in range(50):
  c = 0
  arr = list(f)
  for i in range(n):
    c += arr[i] // s
    arr[i] /= (c+1)
    
  step = step//2
  step = max(1, step)
 
  if c<=k:
    s -= step
    best = min(best,math.ceil(max(arr)))
  else:
    s += step
      
print(best)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)

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

def g(X, t):
    if X<=t:
        return 0
    return 1+g(t, t)+g(X-t, t)

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

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

print(right)