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:
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 += g(i, t)
    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)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
a = readInts()

a.sort(reverse=True)

def nibu(left,right):
	l = (right-left)//2+left
	ans = 0
	for i in a:
		ans+=math.floor(i/l)
	#print(l, ans, left, right)

	if left<right-1:
		if ans<=k:
			return nibu(left,right-(right-l))
		else:
			return nibu(left+(l-left), right)
	else:
		return left


print(nibu(0,a[0])+1)

Submission status: Runtime Error

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

l=0
h=10**9+10

def check(tar):
    sum=0
    for i in range(len(arr)):
        if arr[i]<=tar:
            continue
        x=arr[i]//tar
        y=round(arr[i]/x)
        sum+=(x-1)
        if y!=tar:
            sum+=1
    if sum<=k:
        return True
    else:
        return False

while l!=h:
    m=(l+h)//2
    if check(m):
        h=m
    else:
        l=m+1
print(l)

Submission status: Runtime Error

Solution code:
# Binary Search

def isOK(i, key):
    '''
    問題に応じて返り値を設定
    '''
    cnt = 0
    for v in a:
        cnt += (v + i - 1) // i - 1

    return cnt <= key


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

def check(A,N,i,K):
    cnt=0
    for j in range(N):
        cnt+=ceil(A[j]/i)-1
    if cnt<=K:
        return 1
    else:
        return -1

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
M=A[-1]
res=[0 for _ in range(M+1)]
i=M//2
d=M//2
if K==0:
    print(M)
else:
    while True:
        d//=2
        res[i]=check(A,N,i,K)
        if i>0 and res[i-1]*res[i]==-1:
            ans=i
            break
        elif i<M and res[i]*res[i+1]==-1:
            ans=i+1
            break
        if res[i]==1:
            i-=d
        else:
            i+=d
    print(ans)
    print(res)

Submission status: Runtime Error

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

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

low=-1
high=10**9+1

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

Submission status: Runtime Error

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

A.sort(reverse=True)

left = 0
right = A[0]

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

print(right)

Submission status: Runtime Error

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

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

print(left)

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=map(int,input().split())
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[i]==maxy:
        c.append(i)
for j in r:
    for k in c:
        if (j,k) not in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Submission status: Runtime Error

Solution code:
# ABC174 E

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

left = 0
right = max(a_l)


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


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

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Submission status: Runtime Error

Solution code:
# ABC174 E

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

left = 0
right = max(a_l)


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


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

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Submission status: Runtime Error

Solution code:
# ABC174 E

import math

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

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        ret += math.ceil(float(a_l[i] / len)) - 1
    return ret


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

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
A = sorted(map(int,input().split()))
start = 0
end = A[-1]
l = (start + end)/2
while int(end) - int(start) >= 1:
   l = (start + end)/2
   count = 0
   for i in range(N):
      q, mod = divmod(A[i], l)
      if mod == 0.0;
         q -= 1
      count += q
   if count > K:
      start = l
   else:
      end = l
ans = (start + end)/2
print(int(end)+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

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

left = 0
right = 10**9

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

bottom, top = 0, max(A)

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

print(top)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
import math
l = 1
r = 10**9
flag = True
while True:
  score = 0
  idx = int((l+r)/2)
  for aa in a:
    score += math.ceil(aa/idx)-1
  if score > k:
    l = idx+1
  elif score <= k:
    r = idx-1
    flag = False
  if l == r:
    break
if flag:
  print(l)
else:
  print(l+1)

Submission status: Runtime Error

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

l = 0
r = max(a)
mid = (r-l)//2
while not r-l == 1:
    c = 0
    for x in a:
        c += x//mid
    if c > k:
        l = mid
    else:
        r = mid
    mid = l+(r-l)//2
c = 0
for x in a:
    c += x//l
if c > k:
    print(r)
else:
    print(l)

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

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

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
from decorator import stop_watch
import math


@stop_watch
def solve(N, K, As):
    ans = max(As)
    l, r = 1, ans
    for _ in range(30):
        m = (l + r) // 2
        cnt = 0
        for A in As:
            cnt += math.ceil(A / m) - 1
        if cnt <= K:
            ans = min(ans, m)
            r = m - 1
        else:
            l = m + 1
    print(ans)


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

Submission status: Runtime Error

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

l = 0
r = max(a)
mid = math.ceil((r-l)/2)
while not r-l == 1:
    c = 0
    for x in a:
        c += x//mid
    if c > k:
        l = mid
    else:
        r = mid
    mid = l+math.ceil((r-l)/2)

c = 0
for x in a:
    c += x//(mid-1)
if c <= k:
    mid -= 1
print(mid)

Submission status: Runtime Error

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

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

left=0
right=10**9+1
ans=float("INF")
while True:
    mid=(left+right)//2
    now=0
    for i in range(N):
        now+=ceil(A[i]/mid)-1

    if now>K:
        if left==mid:
            break
        left=mid
    else:
        ans=min(ans, mid)
        if right==mid:
            break
        right=mid

print(ans)

Submission status: Runtime Error

Solution code:
#coding:utf-8
import math

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

A = [int(y) for y in input().split()]

Ma = max(A)
mi = 0

ans = Ma

def execute(f):
    count = 0
    for i in A:
        count += math.ceil(i / f) - 1
    if count <= K:
        return True
    else:
        return False

while True:
    median = (Ma + mi) // 2
    
    bobo = execute(median)
    
    if bobo:
        ans = min(ans,median)
        Ma = median
    else:
        mi = median + 1
    
    if Ma == mi:
        break

print("{}".format(ans))

Submission status: Runtime Error

Solution code:
#coding:utf-8
import math

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

A = [int(y) for y in input().split()]

Ma = max(A)
mi = 0

ans = Ma

def execute(f):
    count = 0
    for i in A:
        count += (i - 0.01) // f
    if count <= K:
        return True
    else:
        return False

while True:
    median = (Ma + mi) // 2
    
    bobo = execute(median)
    
    if bobo:
        ans = min(ans,median)
        Ma = median
    else:
        mi = median + 1
    
    if Ma == mi:
        break

print("{}".format(ans))

Submission status: Runtime Error

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

x0, x1 = 0, 10**9
while x0 + 1  < x1:
  x = (x0+x1)//2
  suma=0
  for i in a:
    suma += (a//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.0000000001)
        if cnt > K: #ダメだったら
            start = ans
            break
    else: #オッケーだったら
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor((A[i] / ans) - 0.000000000001)

if cnt > K:  # ダメだったら
    print(ans + 1)
else:  # オッケーだったら
    print(ans)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
while abs(start - end) > 1:
    ans = abs(end + start) // 2
    cnt = 0
    for i in range(N):
        cnt += math.floor(A[i]/ans - 0.001)
        if cnt > K: #ダメだったら
            start = ans
            break
    else: #オッケーだったら
        end = ans
        continue

cnt = 0
for i in range(N):
    cnt += math.floor(A[i] / ans - 0.001)

if cnt > K:  # ダメだったら
       print(ans + 1)
else:  # オッケーだったら
    print(ans)

Submission status: Runtime Error

Solution code:
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while (r+l)//2!=r and (r+l)//2!=l:
        if f(a,(l+r)//2)>k:
            l = (l+r)//2
        elif f(a,(l+r)//2)<k:
            r = (l+r)//2
        else:
            break
    while True:
        if f(a,r)<=k:
            r -= 1
        else:
            print(r+1)
            return

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans


def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2
        
        if rr == mid:
            return ll
        
        if cou(x,mid) <= n:
            rr = mid
        else:
            ll = mid+1

def cou(x,le):
    co = 0
    for i in range(len(x)):
        co += -(-x[i]//le) - 1
    return co


n,k = m()

a = l()

left = 0

right = 10**9


aaa = nibu(a,k,right)
print(aaa)

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=1
r=10**9
mid=0

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

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    
    for i in range(len(A)):
        if((A[i])%mid):
           tmp=((A[i])//mid)-1
        else
           tmp=((A[i])//mid)
    if(tmp<=K):
        r=mid
    else:
        l=mid

print(r)

Submission status: Runtime Error

Solution code:
import math

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

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x
count = 0
for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x

for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    print(str(l)+":"+str(r))
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x

for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)

Submission status: Runtime Error

Solution code:
import math

def cut(l,A,K):
    counter = 0
    i = N - 1
    while i >= 0:
        c = A[i] // l
        if c == 0:
            break
        else:
            counter += c
            i -= 1
    if counter <= K:
        return True
    else:
        return False
    
if __name__ == '__main__':
    N,K = map(int,input().split())
    A = [float(a) for a in input().split()]
    A.sort()
    left = 2
    right = math.ceil(A[-1])
    while left <= right:
        middle = (left + right) // 2
        if not cut(middle,A,K):
            left = middle + 1
        else:
            if not cut(middle-1,A,K):
                break
            else:
                right = middle - 1
    print(middle)

Submission status: Runtime Error

Solution code:
import math

def cut(l,A,K):
    counter = 0
    i = N - 1
    while i >= 0:
        c = A[i] // l
        if c == 0:
            break
        else:
            counter += c
            i -= 1
    if counter <= K:
        return True
    else:
        return False
    
if __name__ == '__main__':
    N,K = map(int,input().split())
    A = [float(a) for a in input().split()]
    A.sort()
    left = 2
    right = math.ceil(A[-1])
    while left <= right:
        middle = (left + right) // 2
        print(left,right,middle)
        if not cut(middle,A,K):
            left = middle + 1
        else:
            if not cut(middle-1,A,K):
                break
            else:
                right = middle - 1
    print(middle)

Submission status: Runtime Error

Solution code:
from sys import stdin

N, K = map(int, input().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]

def is_max_len_less_than_input(x,K,A):
  count = 0
  for ln in A:
    count += int(ln/x)
    if count > K:
      return False
  return True

def binary_search(begin,end,K,A):
  while abs(end-begin)>1:
    mid = int((begin+end)/2)
    if is_max_len_less_than_input(mid,K,A):
      end = mid
    else:
      begin = mid
  return mid

print(binary_search(−1,max(A),K,A)+1)
# 最小値は1 => 0除算を回避

Submission status: Runtime Error

Solution code:
from sys import stdin

N, K = map(int, input().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]

def is_max_len_less_than_input(x,K,A):
  count = 0
  for ln in A:
    count += int(ln/x)
    if count > K:
      return False
  return True

def binary_search(begin,end,K,A):
  while abs(end-begin)>1:
    mid = int((begin+end)/2+1)
    if is_max_len_less_than_input(mid,K,A):
      end = mid
    else:
      begin = mid
  return mid

print(binary_search(1,max(A),K,A))
# 最小値は1 => 0除算を回避

Submission status: Runtime Error

Solution code:
from sys import stdin

N, K = map(int, input().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]

def is_max_len_less_than_input(x,K,A):
  count = 0
  for ln in A:
    count += int(ln/x)
    if count > K:
      return False
  return True

def binary_search(begin,end,K,A):
  while abs(end-begin)>1:
    mid = int((begin+end)/2)
    if is_max_len_less_than_input(mid,K,A):
      end = mid
    else:
      begin = mid
  return mid

print(binary_search(1,max(A),K,A))

Submission status: Runtime Error

Solution code:
def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num, logs):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(logs):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a <= K and count_b > K:
      # count_aが最大になれば終了
      return half_num
      break
    elif count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2) + 1



N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max)

Submission status: Runtime Error

Solution code:
def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(len(A)):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a <= K and count_b > K:
      # count_aが最大になれば終了
      return half_num
      break
    elif count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2) + 1



N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K)
print(length_max)

Submission status: Runtime Error

Solution code:
n, k = [int(x) for x in input().rstrip().split(" ")]
logs = list(map(int, input().rstrip().split()))
r = 10**9
l = 0
while l<r:
  m = (l+r)//2
  if sum([(a_log-1)//m for a_log in logs])>k:
    l=m+1
  else:
    r=m

print(r)

Submission status: Runtime Error

Solution code:
n, k = [int(_) for _ in input().rstrip().split(" ")]
logs = list(map(int, input().split()))
r = 10**9
l = 0
while l < r:
  m = (l + r) // 2
  if sum([(a_log - 1)//m for a_log in logs]) > k:
    l = m + 1
  else:
    r = m
print(r)

Submission status: Runtime Error

Solution code:
n, k = [int(_) for _ in input().rstrip().split(" ")]
logs = list(map(int, input().split()))
r = 10**9
l = 0
while l < r:  
  m = (l + r) // 2
  cnt = 0
  for a_log in logs:
    cnt += (a_log - 1)//m
  if cnt > k:
    l = m + 1
  else:
    r = m
print(r)

Submission status: Runtime Error

Solution code:
n, k = [int(_) for _ in input().rstrip().split(" ")]
logs = list(map(int, input().split()))
r = max(logs)
l = 0
while True:
  if l >= r:
    break
  m = (l + r) // 2
  cnt = 0
  for a_log in logs:
    cnt += a_log //m-(a_log % m == 0)
  if cnt > k:
    l = m + 1
  else:
    r = m
print(r)