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: Runtime Error

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
a = lr()
l = 0
r = max(a)+1
def totalK(mid):
    ret = 0
    for num in a:
        ret += ((num+mid-1)//mid-1)
    return ret
mid = 0
while r > l:
    mid = l + (r-l)//2
    nowk = totalK(mid)
    if nowk > k:
        l = mid+1
    else:
        r = mid
print(r)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left,bisect
import math

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

def is_ok(arg):
  L = bisect(A, arg)
  cnt = 0
  for i in range(L, N):
    p, q = divmod(A[i], arg)
    if q == 0:
      cnt += p-1
    else:
      cnt += p
  return cnt <= K

ng = -1
ok = max(A) + 1

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

print(m_bisect(ng, ok))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
 
def isfeasible(L):
  k = 0
  for a in A:
    if a < L:
      break
    if a%L == 0:
      dk = a//L - 1
    else:
      dk = a//L
    k += dk
    if k > K:
      return False
  return True
 
l = 0
r = A[0]

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
 
def isfeasible(L):
  k = 0
  for i in range(N):
    a = A[i]
    if a < L:
      break
    if a%L == 0:
      dk = a//L - 1
    else:
      dk = a//L
    k += dk
    if k > K:
      return False
  return True
 
l = 0
r = A[0]

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
 
def isfeasible(L):
  k = 0
  for i in range(N):
    a = A[i]
    if a < L:
      break
    if a%L == 0:
      dk = a//L - 1
    else:
      dk = a//L
    k += dk
    if k > K:
      return False
  return True
 
l = 0
r = A[0]
if K == 0:
  print(A[0])
else:
  while r-l>0:
    L = (r+l)//2
    if isfeasible(L):
      r = L
    else:
      l = L+1
  print(r)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    for j in range(n):
        res += (L[j]-1)//K[i]
    if res <= k:
        P.append(K[i])
print(min(P))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
    print(mid,cur)
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    for j in range(n):
        res += (L[j]-1)//K[i]
    if res <= k:
        P.append(K[i])
print(min(P))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
 
def isfeasible(L):
  k = 0
  sub = []
  for i in range(N):
    a = A[i]
    if a < L:
      sub.append([a, "small"])
      break
    if a%L == 0:
      dk = a//L - 1
      sub.append([a, dk, "just"])
    else:
      dk = a//L
      sub.append([a, dk, "over"])
    k += dk
    if k > K:
      #print("out")
      return False
  #print("ok")
  return True
 
l = 0
r = A[0]
if K == 0:
  print(A[0])
else:
  while r-l>0:
    L = (r+l)//2
    #print("[", l, ",", r,"]checking ", L)
    if isfeasible(L):
      r = L
    else:
      l = L+1
  print(r)

Submission status: Runtime Error

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N,K = inputlist()
A = inputlist()
left = -1
right = 10**9+1
while right - left > 1:
    mid = (left+right)//2
    count = 0
    for i in range(N):
        count += A[i]//mid
        if A[i] % mid == 0:
            count -=1
    if count > K:
        left = mid
    else:
        right = mid
print(right)

Submission status: Runtime Error

Solution code:
#リストAの丸太を全てx以下にK回以内の切る回数で揃えることができるかを判断する関数。
def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]//x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    #二分探索するよ
    left = 0
    right = A[N-1]
    if right == 1:
        return 1
    mid = 0
    while True:
        mid = int( (left + right)/2 )
        #print(left,mid,right)
        judge = can_or_cannot(A,K,mid)
        #print(left,mid,right,judge)
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            #print(left,mid,right)
            return right

print(main())

Submission status: Runtime Error

Solution code:
#リストAの丸太を全てx以下にK回以内の切る回数で揃えることができるかを判断する関数。
def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]//x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    #二分探索するよ
    left = 0
    right = A[N-1]
    mid = 0
    while True:
        mid = (left + right)//2 
        #print(left,mid,right)
        judge = can_or_cannot(A,K,mid)
        #print(left,mid,right,judge)
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            #print(left,mid,right)
            return right

print(main())

Submission status: Runtime Error

Solution code:
import math

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)
    tA = []
    for a in A:
        tA.append((a, 1))

    for k in range(K):
        #print('rope:' + str(k))
        a, diva = tA[1]
        b, divb = tA[0]
        #print(tA)
        while b/divb > a/diva:
            divb += 1
        B = b/divb
        x = 1
        while x < N:
            xn, divx = tA[x]
            if xn/divx < B:
                break
            x += 1
        if x != N:
            tA.insert(x, (b, divb))
        else:
            tA.append((b, divb))
        tA = tA[1:]
        #print(tA)
    print(math.ceil(tA[0][0]/tA[0][1]))




if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
x0=0
x1=max(a)
while(1):
    sum=0
    mid=(x0+x1)//2
    for i in range(n):
        sum+=math.ceil(a[i]/mid)-1
    if(sum<=k):
        x1=mid
    if(sum>k):
        x0=mid
    if(x0+1==x1):
        print(x1)
        break

Submission status: Runtime Error

Solution code:
import math

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)
    tA = []
    for a in A:
        tA.append((a, 1))

    for k in range(K):
        print('rope:' + str(k))
        a, diva = tA[1]
        b, divb = tA[0]
        print(tA)
        while b/divb > a/diva:
            divb += 1
        B = b/divb
        x = 1
        while x < N:
            xn, divx = tA[x]
            if xn/divx < B:
                break
            x += 1
        if x != N:
            tA.insert(x, (b, divb))
        else:
            tA.append((b, divb))
        tA = tA[1:]
        print(tA)
    print(math.ceil(tA[0][0]/tA[0][1]))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import floor, ceil
N = int(input())
WHITE = 0
RED = 1
str = list(map(str, list(input())))
r = []
w = []

for i in range(N):
  w.append(i) if str[i] == "W" else r.append(i)
  str[i] = WHITE if str[i] == "W" else RED
r.reverse()

max_count = max(len(r), len(w))
count = 0
for i in range(max_count):
  if r[i] - w[i] < 0:
    count = i
    break

print(count)

Submission status: Runtime Error

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=0
h=max(As)
while l < h:
    mid = (l+h)//2
    if isltK(K,mid):
        h=mid
    else:
        l=mid+1
print(l)

Submission status: Runtime Error

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 = -1, 1000000000

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

    return r

print(solve())

Submission status: Runtime Error

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

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

print(r)

Submission status: Runtime Error

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 = d_max / 2

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

if check(math.ceil(d_min)):
    print(math.ceil(d_min))
else:
    print(math.ceil(d_min)+1)

Submission status: Runtime Error

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 = max(leng)

d_min = 0
d_max = d

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

if check(math.ceil(d_min)):
    print(math.ceil(d_min))
else:
    print(math.ceil(d_min)+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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:
    m = sum(list(map(lambda x: x // L, A)))
    if m <= k:
        e = L
        L = (e + b) // 2
    else:
        b = L
        L = (e + b) // 2
print(e)

Submission status: Runtime Error

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

ans_max = max(A_list)
ans_min = 1

while 1:    
    if ans_max - ans_min <= 4:
        break
    
    temp_ans = ans_min + (ans_max - ans_min)//2
    temp_K = sum([math.ceil(A/temp_ans)-1 for A in A_list])
    
    if temp_K > K:
        ans_min = temp_ans
    else:
        ans_max = temp_ans
        
for i in range(ans_min,ans_max+1):
    temp_K = sum([math.ceil(A/i)-1 for A in A_list])

    if temp_K == K:
        print(i)
        break

Submission status: Runtime Error

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):
    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:

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: Runtime Error

Solution code:
#リストAの丸太を全てx以下にK回以内の切る回数で揃えることができるかを判断する関数。
def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]//x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    #二分探索するよ
    left = 0
    right = A[N-1]
    mid = 0
    while True:
        mid = int( (left + right)/2 )
        #print(left,mid,right)
        judge = can_or_cannot(A,K,mid)
        #print(left,mid,right,judge)
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            #print(left,mid,right)
            return right

print(main())

Submission status: Runtime Error

Solution code:
#リストAの丸太を全てx以下にK回以内の切る回数で揃えることができるかを判断する関数。
def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]//x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    #二分探索するよ
    left = 0
    right = A[N-1]
    mid = 0
    while True:
        mid = int( (left + right)/2 )
        print(left,mid,right)
        judge = can_or_cannot(A,K,mid)
        print(left,mid,right,judge)
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            print(left,mid,right)
            return right

print(main())

Submission status: Runtime Error

Solution code:
#リストAの丸太を全てx以下にK回以内の切る回数で揃えることができるかを判断する関数。
def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]%x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    #二分探索するよ
    left = 0
    right = A[N-1]
    mid = 0
    while True:
        mid = int( (left + right)/2 )
        judge = can_or_cannot(A,K,mid)
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            return right

print(main())

Submission status: Runtime Error

Solution code:
def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    '''
    ok = 10 ** 9 + 1  # 条件を満たすindexの上限値/下限値
    ng = -1           # 条件を満たさないindexの下限値/上限値
    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: Runtime Error

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

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


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

print(binary_search(k))

Submission status: Runtime Error

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

a = list(map(int, input().split()))
a.sort(reverse=True)
lst = []
for i in a:
    lst.append([-i, 0])

heapq.heapify(lst)

i = 0
while i < K:
    p1 = heapq.heappop(lst)
    p2 = heapq.heappop(lst)
    k = int(p1[0]*p1[1]/p2[0] - p1[1] + 1)
    if i + k <= K:
        p1[0] = p1[0] * (p1[1] + 1) / (p1[1] + 1 + k)
        p1[1] += k
        i += k
    else:
        p1[0] = p1[0] * (p1[1] + 1) / (p1[1] + 1 + K - i)
        p1[1] += K - i
        i = K
        
    heapq.heappush(lst, p1)
    heapq.heappush(lst, p2)

p = heapq.heappop(lst)
print(math.ceil(-p[0]))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main()
{
    int n, k;
    cin >> n >> k;
    long long sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        sum += a[i];
    }
    long long l = 1, r = sum;
    while (l < r)
    {
        long long m = l + (r - l) / 2;
        bool valid = true;
        long long cuts = 0;
        for (int i = 0; i < n; ++i)
        {
            cuts += ceil(a[i] / (long double)m) - 1;
            if (cuts > k)
            {
                valid = false;
                break;
            }
        }
        if (valid)
        {
            r = m;
        }
        else
        {
            l = m+1;
        }
    }
    cout << r;
}

Submission status: Runtime Error

Solution code:
import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += (math.ceil(A[i] / mid) - 1)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

if K == 0:  print(max(A))
else:
    left = max(A)
    right = -1
    ret = binary_search(right, left)
    print(ret)

Submission status: Runtime Error

Solution code:
import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += (math.floor(A[i] / mid) - 1)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

if K == 0:  print(max(A))
else:
    left = max(A) + 1
    right = -1
    ret = binary_search(right, left)
    print(ret)

Submission status: Runtime Error

Solution code:
import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += math.floor(A[i] / mid)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

if K == 0:  print(max(A))
else:
    left = max(A)
    right = -1
    ret = binary_search(right, left)
    print(ret)

Submission status: Runtime Error

Solution code:
import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += math.floor(A[i] / mid)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

left = max(A)
right = -1
ret = binary_search(right, left)
print(ret)

Submission status: Runtime Error

Solution code:
import math

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N, K = cin()
A = cin()

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += math.floor(A[i] / mid)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

left = max(A)
right = -1
ret = binary_search(right, left)
print(ret)

Submission status: Runtime Error

Solution code:
import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
a=max(A)
l=0
y=copy.copy(a)
a=a-1
while l<=a:
    x=(l+a)//2
    m=0
    for i in range(N):
        if A[i]%x==0:
            m+=A[i]//x-1
        else:
            m+=A[i]//x
    if m<=K:
        a=x-1
        y=copy.copy(x)
    else:
        l=x+1
print(y)

Submission status: Runtime Error

Solution code:
import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
a=max(A)
l=0
y=copy.copy(a)
a=a-1
while l<=a:
    x=(l+a)//2
    m=sum([A[i]//x for i in range(N)]) # x以下にするための回数
    if m<=K:
        a=x-1
        y=copy.copy(x)
    else:
        l=x+1
print(y)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split()[:2])
arr = list(map(int, input().split()[:N]))


def pos(X):
    sum = 0
    for i in arr:
        sum += int(i/X)
        if i % X == 0:
            sum -= 1
    return sum <= K


low = 0
high = 10 ** 9
mid = 0
ans = 10**9

while low <= high:
    mid = int((low+high)/2)
    # print(low, mid, high)
    if(pos(mid)):
        ans = mid
        high = mid-1
    else:
        low = mid+1
    # print(pos(mid))
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split()[:2])
arr = list(map(float, input().split()[:N]))


def pos(X):
    sum = 0
    for i in arr:
        sum += int((i-1)/X)
    return sum <= K


low = 0
high = 10 ** 9
mid = 0
ans = 10**9

while low <= high:
    mid = int((low+high)/2)
    # print(low, mid, high)
    if(pos(mid)):
        ans = mid
        high = mid-1
    else:
        low = mid+1
    # print(pos(mid))
print(ans)

Submission status: Runtime Error

Solution code:
from math import ceil

N,K,*A = map(int, open(0).read().split())
left = 1
right = max(A)
while left != right:
    mid = (left+right) // 2
    temp = 0
    for x in A:
        temp += ceil(x/mid) - 1
        if temp > K:
            left = mid + 1
            break
    else:
        right = mid
for i in range(left-1,left+2):
    temp = 0
    for x in A:
        temp += ceil(x/i) - 1
        if temp > K:
            break
    else:
        print(i)
        break

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
mid = (left+right)//2
minN = right
result = mid
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
        if minN>mid:
            minN = mid
            result = mid
    elif count > K:
        left = mid
print(result)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
mid = (left+right)//2
minN = right
result = right
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
        if minN>mid:
            minN = mid
            result = mid
    elif count > K:
        left = mid
print(result)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
mid = (left+right)//2
minN = right
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
        if minN>mid:
            minN = mid
            result = mid
    elif count > K:
        left = mid
print(result)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
mid = (left+right)//2
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
    elif count > K:
        left = mid
    else:
        flag = False
print(mid)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
    elif count > K:
        left = mid
    else:
        flag = False
print(mid)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = a[-1]

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

print(r)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
right = maxA
left = 0
while(right-left>1):
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count > K:
        left = mid
    elif count <= K:
        right = mid
print(mid)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
num = 0
right = maxA
left = 0
while(right-left>1):
    num = left+math.floor((right-left)*0.5)
    count = 0
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
    if count > K:
        left = num
    elif count <= K:
        right = num
count = 0
num = right
for i in range(len(A)):
    count += math.ceil(A[i]/num)-1
if count!=K:
    num = left
    count = 0
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
print(num)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
num = 0
right = maxA
left = 0
while(right-left>1):
    num = left+math.floor((right-left)*0.5)
    count = 0
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
    if count > K:
        left = num
    elif count < K:
        right = num
count = 0
num = right
for i in range(len(A)):
    count += math.ceil(A[i]/num)-1
if count!=K:
    num = left
    count = 0
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
print(num)