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: Wrong Answer

Solution code:
from math import ceil

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

def C(x):
  return sum([A[i]//x for i in range(N)]) <= K
  
def binary_search2(func, n_min, n_max):
    left,right=n_min,n_max
    y_left, y_right = func(left), func(right)
    while True:
        middle = (left+right)//2
        y_middle = func(middle)
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left
  
print(binary_search2(C, 1, max(A))+1)

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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 >= 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: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = sorted(map(int,input().split()))
start = 0
end = A[-1]
l = (start + end)/2
while end - start >= 0.0000001:
   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: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = sorted(map(int,input().split()))
start = 0
end = A[-1]
l = (start + end)/2
while end - start >= 0.001:
   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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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=1
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: Wrong Answer

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(30):
  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=ue
    L=[waru(i,n)-1 for i in A]
    if sum(L)>K:
      print(n-1)
      exit()
    else:
      print(n)
      exit()

Submission status: Wrong Answer

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(30):
  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(n)
    exit()
  elif ue-sita==1:
    n=ue
    L=[waru(i,n)-1 for i in A]
    if sum(L)>K:
      print(n-1)
      exit()
    else:
      print(n)
      exit()

Submission status: Wrong Answer

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(n)
    exit()
  elif ue-sita==1:
    n=ue
    L=[waru(i,n)-1 for i in A]
    if sum(L)>K:
      print(n-1)
      exit()
    else:
      print(n)
      exit()

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = 10**10

while( max_A - min_A > 1):
  now = (min_A + max_A) // 2
  temp = 0
  for i in A:
    if i > now:
      temp += (i // now)
  if temp > K:
    min_A = now
  else:
    max_A = now
print(int(min_A) + 1)

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A) + 1

while( max_A - min_A > 1):
  now = (min_A + max_A) // 2
  temp = 0
  for i in A:
    if i > now:
      temp += (i // now)
  if temp > K:
    min_A = now
  else:
    max_A = now
print(int(min_A) + 1)

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A) + 1

while( max_A - min_A > 1):
  now = (min_A + max_A) // 2
  temp = 0
  for i in A:
    temp += (i // now)
  if temp > K:
    min_A = now
  else:
    max_A = now
print(int(min_A) + 1)

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A) + 1

while( max_A - min_A > 1):
  now = (min_A + max_A) // 2
  temp = 0
  for i in A:
    temp += (i // now)
  if temp > K:
    min_A = now
  else:
    max_A = now
print(min_A, max_A)
print(int(min_A) + 1)

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A)

while( max_A - min_A > 1):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += (i // now)
  if temp > K:
    min_A = now
  else:
    max_A = now
print(math.ceil((min_A + max_A)/2))

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A)

while( max_A - min_A > 1):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += int(i / now)
  if temp > K:
    min_A = now
  else:
    max_A = now
  
print(int(min_A) + 1)

Submission status: Wrong Answer

Solution code:
import math

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

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A)

while( int(max_A) - int(min_A) != 0):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += int(i / now)
  if temp > K:
    min_A = now
  else:
    max_A = now
  
print(int(min_A) + 1)

Submission status: Wrong Answer

Solution code:
import math

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

def quicksort(arr):
  if len(set(arr)) <= 1:
    return arr
  left = []
  center = arr.pop(0)
  right = []
  for i in arr:
    if i < center:
      left.append(i)
    else:
      right.append(i)
  left = quicksort(left)
  right = quicksort(right)
  left.append(center)
  left.extend(right)
  return left

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
max_A = max(A)

while( int(max_A) - int(min_A) != 0):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += int(i / now)
  if temp > K:
    min_A = now
  else:
    max_A = now
  
print(math.ceil(min_A))

Submission status: Wrong Answer

Solution code:
import math

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

def quicksort(arr):
  if len(set(arr)) <= 1:
    return arr
  left = []
  center = arr.pop(0)
  right = []
  for i in arr:
    if i < center:
      left.append(i)
    else:
      right.append(i)
  left = quicksort(left)
  right = quicksort(right)
  left.append(center)
  left.extend(right)
  return left

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = 0
min_K = 0
max_A = max(A)
max_K = 2 * K

while( int(max_A) - int(min_A) != 0):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += int(i / now)
  if temp > K:
    min_A = (min_A + now) / 2
    max_K = temp
  else:
    max_A = (now + max_A) / 2
    min_K = temp
  
print(math.ceil(min_A))

Submission status: Wrong Answer

Solution code:
import math

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

def quicksort(arr):
  if len(set(arr)) <= 1:
    return arr
  left = []
  center = arr.pop(0)
  right = []
  for i in arr:
    if i < center:
      left.append(i)
    else:
      right.append(i)
  left = quicksort(left)
  right = quicksort(right)
  left.append(center)
  left.extend(right)
  return left

if K == 0:
  print(int(max(A)))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = min(A)/K
min_K = 0
max_A = max(A)
max_K = 2 * K

while( int(max_A) - int(min_A) != 0):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += int(i / now)
  if temp > K:
    min_A = (min_A + now) / 2
    max_K = temp
  else:
    max_A = (now + max_A) / 2
    min_K = temp
  
print(math.ceil(min_A))

Submission status: Wrong Answer

Solution code:
import math

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

def quicksort(arr):
  if len(set(arr)) <= 1:
    return arr
  left = []
  center = arr.pop(0)
  right = []
  for i in arr:
    if i < center:
      left.append(i)
    else:
      right.append(i)
  left = quicksort(left)
  right = quicksort(right)
  left.append(center)
  left.extend(right)
  return left

A = quicksort(A)

if K == 0:
  print(int(A[-1]))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = A[0]/K
min_K = 0
max_A = A[-1]
max_K = 2 * K

while( int(max_A) - int(min_A) != 0):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += 1 + int(i / now)
  if temp > K:
    min_A = (min_A + now) / 2
    max_K = temp
  else:
    max_A = (now + max_A) / 2
    min_K = temp
  
print(math.ceil(min_A))

Submission status: Wrong Answer

Solution code:
import math

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

def quicksort(arr):
  if len(set(arr)) <= 1:
    return arr
  left = []
  center = arr.pop(0)
  right = []
  for i in arr:
    if i < center:
      left.append(i)
    else:
      right.append(i)
  left = quicksort(left)
  right = quicksort(right)
  left.append(center)
  left.extend(right)
  return left

A = quicksort(A)

if K == 0:
  print(int(A[-1]))
  exit()

if N == 1:
  print(math.ceil(A[0]/K))
  exit()


min_A = A[0]/K
min_K = 0
max_A = A[-1]
max_K = 2 * K

while( int(max_A) - int(min_A) != 0):
  now = (min_A + max_A) / 2
  temp = 0
  for i in A:
    temp += math.floor(i / now)
  if temp > K:
    min_A = (min_A + now) / 2
    max_K = temp
  else:
    max_A = (now + max_A) / 2
    min_K = temp
  
print(math.ceil(min_A))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
A = sorted(A, reverse=True)

l = 1
r = max(A)+1
def cut(l, k):
    # 長さlの丸太を最大とすることができるかどうかを返す
    for a in A:
        if a > l:
            k -= (-(-a//l) - 1)
    return k >= 0

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

Submission status: Wrong Answer

Solution code:
n,k,*a = map(int,open(0).read().split())
def func(b):
  c = k
  for i in a:
    if b == 0:
      c -= i
    else:
      c -= (i-1)//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: Wrong Answer

Solution code:
n,k,*a = map(int,open(0).read().split())
def func(b):
  c = k
  for i in a:
    if b == 0:
      c -= (i+1)
    else:
      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: Wrong Answer

Solution code:
n,k,*a = map(int,open(0).read().split())
def func(b):
  c = k
  for i in a:
    if b == 0:
      c -= i+1
    else:
      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: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    ok = max(a)
    ng = 0
    while abs(ok-ng) >= 0.01:
        mid = (ok+ng) / 2
        cnt = 0
        for i in range(n):
            if a[i] > mid:
                cnt += math.ceil(a[i]/mid) - 1
            if cnt > k:
                break
        if cnt > k:
            ng = mid
        else:
            ok = mid
    print(math.ceil(ok))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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 m == 0:
    if check(1):
      ans.append(1)
    break
  if check(m):
    mx = m - 1
    ans.append(m)
  else:
    mn = m + 1
print (min(ans))

Submission status: Wrong Answer

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 m == 0:
    break
  if check(m):
    mx = m - 1
    ans.append(m)
  else:
    mn = m + 1
print (min(ans))

Submission status: Wrong Answer

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 m == 0:
    break
  if check(m):
    mx = m - 1
    ans.append(m)
  else:
    mn = m + 1
print (min(ans))

Submission status: Wrong Answer

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

low = 0
high = max(a)

while low + 1 < high:
    print(low, high)
    mid = (low + high) // 2
    m = 0
    for x in a:
        m += (x - 1) // mid
    
    if m <= k:
        high = mid
    else:
        low = mid

print(high)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=max(a),1
while l-r>1:
    t=(l+r)//2
    c=0
    for i in a:
        c+=(i-1)//t
    if c>k:
        r=t
    else:
        l=t
print(l)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=max(a),1
while l-r>1:
    t=(l+r)//2
    c=0
    for i in a:
        c+=i//t
    if c>k:
        r=t
    else:
        l=t
print(l)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=max(a)+1,0
while l-r>1:
    t=(l+r)//2
    c=0
    for i in a:
        c+=i//t
    if c>k:
        r=t
    else:
        l=t
print(l)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=max(a),0
while l-r>1:
    t=(l+r)//2
    c=0
    for i in a:
        c+=i//t
    if c>k:
        r=t
    else:
        l=t
print(l)

Submission status: Wrong Answer

Solution code:
import math

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

def seikai(x):
    count = 0
    for i in range(n):
        count += math.ceil(a[i] / x) - 1

    if(count <= k):
        return 1
    else:
        return 0

l = 1
r = 10 ** 9
while(r - l > 1):
    temp = (r + l) // 2
    if(seikai(temp) == 1):
        r = temp
    else:
        l = temp

print(r)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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
print(r)

Submission status: Wrong Answer

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

l = 1
r = max(a)
mid = l+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)
print(mid)

Submission status: Wrong Answer

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)
print(mid)

Submission status: Wrong Answer

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


def cut_num(a, cut_length):
    return math.ceil(a/cut_length) - 1


"""cut length N binary search
if cut num > K, search more longer cut length,
"""
l = 1
r = max(As)

ans = r
while r-l > 1:
    m = (l+r)/2
    current_cut_num = sum([cut_num(a, m) for a in As])
    if current_cut_num <= K:
        ans = min(ans, m)
        r = m
    else:
        l = m

print(int(ans))

Submission status: Wrong Answer

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


def cut_num(a, cut_length):
    if a % cut_length == 0:
        return (a // cut_length) - 1
    else:
        return (a // cut_length)


"""cut length N binary search
if cut num > K, search more longer cut length,
"""
l = 0
r = 10e9


while r-l > 1:
    m = (l+r)/2
    current_cut_num = sum([cut_num(a, m) for a in As])
    if current_cut_num > K:
        l = m
    else:
        r = m

print(int(r))

Submission status: Wrong Answer

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


def cut_num(a, cut_length):
    if a % cut_length == 0:
        return (a // cut_length) - 1
    else:
        return a // cut_length


"""binary search
"""
l = 0
r = 10e9


while r-l > 1:
    n = (l+r)/2
    current_cut = sum([cut_num(a, n) for a in As])
    
    if current_cut > K:
        l = n
    else:
        r = n

print(math.ceil(l))

Submission status: Wrong Answer

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 += (i//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)

Submission status: Wrong Answer

Solution code:
def count(N,K,mid,a):
    cnt = 0
    for i in range(N):
        cnt += a[i]//mid
    if cnt > K:
        return False
    else:
        return True

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    low = 1
    high = 10**9+1
    mid = (low+high)//2

    while high > low+1:
        if count(N,K,mid,a):
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    if count(N,K,low,a):
        print(low)
    else:
        print(high)

main()

Submission status: Wrong Answer

Solution code:
def count(N,K,mid,a):
    cnt = 0
    for i in range(N):
        cnt = a[i]//mid
    if cnt > K:
        return False
    else:
        return True

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    low = 1
    high = 10**9
    mid = (low+high)//2

    while high > low+1:
        if count(N,K,mid,a):
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    if count(N,K,low,a):
        print(high)
    else:
        print(low)

main()

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    count = 0
    for i in range(n):
        count += a[i] // arg
    return count <= k

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

n, k = MAP()
a = LIST()
if k == 0:
    print(max(a))
else:
    print(meguru_bisect(0, max(a)+1))

Submission status: Wrong Answer

Solution code:
import math

def cut(l,A,K):
    counter = 0
    i = N - 1
    if l == 0:
        return False
    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 = 0
    right = math.ceil(A[-1])
    while left <= right:
        middle = (left + right) // 2
        if cut(middle,A,K):
            if not cut(middle-1,A,K):
                break
            else:
                right = middle - 1
        else:
            left = middle + 1
    print(middle)

Submission status: Wrong Answer

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:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        elif g<k:
            r = mid-1
        else:
            r = mid
    if f(a,l)<=k:
        print(l)
    else:
        print(r)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        elif g<k:
            r = mid-1
        else:
            r = mid
    print(r)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

def cut(l,A,K):
    counter = 0
    i = N - 1
    if l == 0:
        return False
    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 = 0
    right = math.ceil(A[-1])
    while left <= right:
        middle = (left + right) // 2
        if cut(middle,A,K):
            if not cut(middle-1,A,K):
                break
            else:
                right = middle - 1
        else:
            left = middle + 1
    print(middle-1)

Submission status: Wrong Answer

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:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid
        else:
            r = mid
    print(r)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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=0
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)):
        tmp+=(A[i]//mid)
    if(tmp<=K):
        r=mid
    else:
        l=mid

print(r)

Submission status: Wrong Answer

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)):
        tmp=(A[i]//(mid+1))+1
    if(K<=tmp):
        l=mid
    else:
        r=mid

print(r)

Submission status: Wrong Answer

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
    if x == 0:
        break

    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
ans = x
if(x!= 0 and l != 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: Wrong Answer

Solution code:
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

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

lx = 0
rx = max(A)
ans = 0
while (int(lx) < int(rx)):
    x = (rx + lx) / 2
    dprint("lx, x, rx = ", lx, x, rx)
    n = 0
    for i in range(len(A)):
        #n += math.ceil(A[i] / x) - 1
        n += A[i] // x
        if n > k: break
    dprint("n = ", n)
    if n <= k:
        dprint(" smaller x")
        rx = x
    else:
        dprint(" cut less, bigger x")
        lx = x

ans = math.ceil(rx)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

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

lx = 0
rx = max(A)
ans = 0
while (int(lx) < int(rx)):
    x = (rx + lx) / 2
    dprint("lx, x, rx = ", lx, x, rx)
    n = 0
    for i in range(len(A)):
        n += math.ceil(A[i] / x) - 1
    dprint("n = ", n)
    if n <= k:
        dprint(" smaller x")
        rx = x
    else:
        dprint(" cut less, bigger x")
        lx = x

ans = math.ceil(lx)
print(ans)