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:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]
    if(k == 0):
        print(MA)
        return
    if(n == 1):
        print(MA//k if MA%k == 0 else MA//k + 1)
        return
    while(True):
        m = mi + (MA - mi)//2
        if(MA == 1):
            print(1)
            return
        #print(mi,m,MA)
        count = 0
        for i in a:
            count += i//m
        if(MA < mi):
            print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m-1
        




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

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

ng_len = 1
ok_len = 1000000000


def possible_len(length: int, log: list, k: int):
    count = 0
    for i in range(N):
        count += math.ceil(log[i] / length) - 1
    if count <= k:
        return True
    else:
        return False


while ok_len - ng_len > 1:
    mid = (ng_len + ok_len) // 2
    if possible_len(mid, logs, K):
        ok_len = mid
    else:
        ng_len = mid


# if possible_len(ng_len, logs, K):
#     print(ng_len)
# else:
print(ok_len)

Submission status: Wrong Answer

Solution code:
import math

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

ng_len = 1
ok_len = 1000000000


def possible_len(length: int, log: list, k: int):
    count = 0
    for i in range(N):
        count += math.ceil(log[i] / length) - 1
    if count <= k:
        return True
    else:
        return False


while ok_len - ng_len > 1:
    mid = (ng_len + ok_len) // 2
    if possible_len(mid, logs, K):
        ok_len = mid
    else:
        ng_len = mid


# if possible_len(ng_len, logs, K):
#     print(ng_len)
# else:
    print(ok_len)

Submission status: Wrong Answer

Solution code:
def mbisect(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


def check(mid):
    cnt = 0
    for i in a:
        cnt += (i + mid - 1) // mid - 1
    return cnt <= k


n, k = map(int, input().split())
a = tuple(map(int, input().split()))
print(mbisect(10 ** 9, 1))

Submission status: Wrong Answer

Solution code:
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while maxVal - minVal >= 0.5:
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

print(math.ceil(maxVal))

Submission status: Wrong Answer

Solution code:
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while maxVal - minVal >= 0.5:
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

print(math.ceil(minVal))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10 ** 9

while r-l > 1 :
    m = (l+r)//2 
    b = list(map(lambda x: -(-x//m) - 1 ,a))
    ans = sum(b)
    if ans <= k :
        r = m
    else :
        l = m
    print(l,r)

print(r)

Submission status: Wrong Answer

Solution code:
import sys
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k ==0:
  print(max(a))
  sys.exit()
def check(t):
  ans = 0
  if t==0:
    return False
  for aa in a:
    if aa > t:
      ans += aa//t
  return ans <= k
max = 10**9+1
min = 0
while max-min>1:
  mid = (max+min)/2
  if check(mid):
    max = mid
  else:
    min = mid
print(math.ceil(max))

Submission status: Wrong Answer

Solution code:
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while maxVal - minVal >= 1:
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

print(math.ceil(minVal))

Submission status: Wrong Answer

Solution code:
import sys
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k ==0:
  print(max(a))
  sys.exit()
def check(t):
  ans = 0
  if t==0:
    return False
  for aa in a:
    if aa > t:
      ans += aa//t
  if ans > k:
    return False
  else:
    return True
max = 10**9+1
min = 0
while max-min>0.001:
  mid = (max+min)/2
  if check(mid):
    max = mid
  else:
    min = mid
print(math.ceil(max))

Submission status: Wrong Answer

Solution code:
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while maxVal - minVal >= 1:
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

print(math.ceil((maxVal + minVal) / 2))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math


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


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ok = max(A)
    ng = 1

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

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k ==0:
  print(max(a))
  sys.exit()
def check(t):
  ans = 0
  for aa in a:
    if aa > t:
      ans += aa//t
  if ans > k:
    return False
  else:
    return True
max = 10**9
min = 0
while max-min>0.001:
  mid = (max+min)/2
  if check(mid):
    max = mid
  else:
    min = mid
print(math.ceil(max))

Submission status: Wrong Answer

Solution code:
import math
N,K=map(int,input().split())
L = list(map(int, input().split()))
L.sort(reverse=True)
def binary_search(list, item):
    low = 0
    high = L[0]
    while high-low>1:
        mid=(low+high)//2
        p=0
        for i in range(len(L)):
            p+=math.ceil(L[i]/mid)-1
        if p==item:
            return mid
            break
        else:
            if p>item:
                low=mid
            else:
                high=mid
    return high
if K==0:
    print(L[0])
else:
    print(binary_search(L,K))

Submission status: Wrong Answer

Solution code:
import math

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

min_len = 1
max_len = 1000000000


def possible_len(length: int, log: list, k: int):
    count = 0
    for i in range(N):
        count += math.ceil(log[i] / length) - 1
    if count <= k:
        return True
    else:
        return False


while max_len - min_len > 1:
    ans = (min_len + max_len) // 2
    if possible_len(ans, logs, K):
        max_len = ans
    else:
        min_len = ans

print(max_len)

Submission status: Wrong Answer

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 check(t):
  ans = 0
  for aa in a:
    if aa > t:
      ans += aa//t
  if ans > k:
    return False
  else:
    return True
max = 10**9
min = 0
while max-min>1:
  mid = (max+min)/2
  if check(mid):
    max = mid
  else:
    min = mid
print(int(max)+1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math


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


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ng = max(A)
    ok = 1

    while abs(ok - ng) > 1:
        mid = abs(ok + ng) // 2
        count = 0
        for i in range(N):
            count += math.floor(A[i] / mid)
        if count > K:
            ok = mid
        else:
            ng = mid

    print(ng)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

s = [int(a) for a in input().split(" ")]
N = s[0]
K = s[1]
As = [int(a) for a in input().split(" ")]
As = sorted(As)[::-1]


def func(minimun):
    count = 0
    for A in As:
        if(A > minimun):
            count += A // minimun
            if(count > K):
                return False
        else:
            return True
    return True


bound = [0, As[0]]
while(True):
    i = (bound[0] + bound[1]) / 2
    if(func(i)):
        bound[1] = i
    else:
        bound[0] = i

    if(bound[1] - bound[0] <= 0.001):
        print(math.ceil(bound[0]))
        break

Submission status: Wrong Answer

Solution code:
import math

s = [int(a) for a in input().split(" ")]
N = s[0]
K = s[1]
As = [int(a) for a in input().split(" ")]
As = sorted(As)[::-1]


def func(minimun):
    count = 0
    for A in As:
        if(A > minimun):
            count += A // minimun
            if(count > K):
                return False
        else:
            return True
    return True


bound = [0, As[0]]
while(True):
    i = (bound[0] + bound[1]) / 2
    if(func(i)):
        bound[1] = i
    else:
        bound[0] = i

    if(bound[1] - bound[0] <= 0.1):
        print(math.ceil(bound[0]))
        break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math

N,K = map(int,sys.stdin.readline().split())
a = list(map(int,sys.stdin.readline().split())) # single line with multi param
a.sort(reverse=True)

ng = 0
ok = a[0]

def isOK(v):
    # within range
    # return key <= a[index]
    k = K
    i = 0
    while k >= 0 and i < N:
        #print("?",v,i,a[i],k,math.ceil(a[i] / v) -1,k - (math.ceil(a[i]/v) - 1))
        k = k - (math.ceil(a[i]/v) - 1)
        i += 1
    return k >= 0

while abs(ng-ok) > 0.5:
    mid = (ok+ng)/2
    #print(mid,isOK(mid))
    if isOK(mid):#ok condition?
        ok = mid #move ok
    else:
        ng = mid
#294924427
print(math.ceil(ok))

# a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
# heapq.heapify(a)# a == [1,2,3]
# for _ in range(K):
#     _,ori,di = heapq.heappop(a)
#     heapq.heappush(a, [-(ori)/(di+1),ori,di+1])
# print(math.ceil(-a[0][0]))

Submission status: Wrong Answer

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

l=0
r=1e9+5

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math

N,K = map(int,sys.stdin.readline().split())
a = list(map(int,sys.stdin.readline().split())) # single line with multi param
a.sort(reverse=True)

ng = 0
ok = a[0]

def isOK(v):
    # within range
    # return key <= a[index]
    k = K
    i = 0
    while k >= 0 and i < N:
        #print("?",v,i,a[i],k,math.ceil(a[i] / v) -1,k - (math.ceil(a[i]/v) - 1))
        k = k - max(0,(math.ceil(a[i]/v) - 1))
        i += 1
    return k >= 0

while abs(ng-ok) > 0.5:
    mid = (ok+ng)/2
    #print(mid,isOK(mid))
    if isOK(mid):#ok condition?
        ok = mid #move ok
    else:
        ng = mid
#294924427
print(math.ceil(ok))

# a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
# heapq.heapify(a)# a == [1,2,3]
# for _ in range(K):
#     _,ori,di = heapq.heappop(a)
#     heapq.heappush(a, [-(ori)/(di+1),ori,di+1])
# print(math.ceil(-a[0][0]))

Submission status: Wrong Answer

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

mi = 1
ma = 10**9
while(ma - mi != 1):
    c = 0
    mid = (ma + mi) // 2
    for i in range(N):
        c += A[i] // mid - (A[i] % mid == 0)
    if c > K:
        mi = mid
    else:
        ma = mid
print(ma)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
def check(t):
  ans = 0
  for aa in a:
    if aa > t:
      ans += aa//t
max = 10**9
min = 0
while max-min>1:
  mid = (max+min)/2
  if check(mid):
    max = mid
  else:
    min = mid
print(max)

Submission status: Wrong Answer

Solution code:
from heapq import heapify,heappop,heappush
from math import ceil

def solve(A,N,K):
    ans_max,ans_min = max(A),1

    if cutable(A,N,K,1):
        return 1
    
    while True:
        if cutable(A,N,K,(ans_max+ans_min)//2):
            if ans_max > (ans_max+ans_min)//2:
                ans_max = (ans_max+ans_min)//2
            else:
                return ans_max
        else:
            if ans_min < (ans_max+ans_min)//2:
                ans_min = (ans_max+ans_min)//2
            else:
                return ans_max

def cutable(A,N,K,div):
    #K回までの切断で全部を長さdiv以下にできるかどうか
    cnt = 0
    for i in range(N):
        cnt += A[i]//div
        if cnt > K:
            return False

    return True

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

    ans = solve(A,N,K)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#import numpy as np
#import collections
#import math

#f = open('./input_E.txt')
#
#N,K = map(int, f.readline().split())
#A = list(map(int, f.readline().split()))

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

A.sort(reverse=True)

if N==1 or K==0:
    ans = A[0]
else:    
    All_length = sum(A)
    KK = K+N-1
    lm = All_length/(KK+1)
    
    k_list = [int(Ai//lm) for Ai in A]
    X_list = [Ai%lm for Ai in A]
    Xmax = max(X_list)

    zero_k = 0
    for i in range(1,N+1):
        if k_list[-i] == 0:
            zero_k +=1
        else:
            break
    
    sum_k = sum(k_list)-(N-zero_k)
    res_cut = K-sum_k
    
    
    if res_cut > 0:
#        think = min(7*(N//res_cut)+1,res_cut)
        ans_kouho = []
#        for i in range(-zero_k,0):
#            ans_kouho.append(A[i])
#        ans_kouho.extend(X_list)
        for i in range(res_cut):
#        for i in range(think):
            if Xmax >= i*lm:
                for j in range(N-zero_k):
#                    ans_kouho.append((X_list[j]-i*lm)/k_list[j]+1)
                    ans_kouho.append(A[j]/(k_list[j]+i))
        
        ans_kouho.sort(reverse=True)
        ans = ans_kouho[res_cut]
        ans = int(ans+1)
    else:
        ans = int(lm+1)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys,collections,heapq,math

N,K = map(int,sys.stdin.readline().split())
a = list(map(int,sys.stdin.readline().split())) # single line with multi param
a.sort(reverse=True)

ng = 0
ok = a[0]

def isOK(v):
    # within range
    # return key <= a[index]
    k = K
    i = 0
    while k >= 0 and i < N:
        #print("?",v,i,a[i],k,math.ceil(a[i] / v) -1,k - (math.ceil(a[i]/v) - 1))
        k = k - max(0,(math.ceil(a[i]/v) - 1))
        i += 1
    return k >= 0

while abs(ng-ok) > 0.25:
    mid = (ok+ng)/2
    #print(mid,isOK(mid))
    if isOK(mid):#ok condition?
        ok = mid #move ok
    else:
        ng = mid
#294924427
print(math.ceil(ok))

# a = [[-b,b,1] for b in tuple(map(int,sys.stdin.readline().split()))] # single line with multi param
# heapq.heapify(a)# a == [1,2,3]
# for _ in range(K):
#     _,ori,di = heapq.heappop(a)
#     heapq.heappush(a, [-(ori)/(di+1),ori,di+1])
# print(math.ceil(-a[0][0]))

Submission status: Wrong Answer

Solution code:
from math import ceil
n, k, *A = map(int, open(0).read().split())
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
X = []
for a in A:
    X.append(ceil(a / ceil(a/t)))
    X.append(ceil(a / int(a/t)))
X.sort()
print(X[k] if k < len(X) else X[-1])

Submission status: Wrong Answer

Solution code:
from heapq import heapify,heappop,heappush
from math import ceil

def solve(A,N,K):
    ans_max,ans_min = max(A),1
    while True:
        if cutable(A,N,K,(ans_max+ans_min)//2):
            if ans_max > (ans_max+ans_min)//2:
                ans_max = (ans_max+ans_min)//2
            else:
                return ans_max
        else:
            if ans_min < (ans_max+ans_min)//2:
                ans_min = (ans_max+ans_min)//2
            else:
                return ans_max

def cutable(A,N,K,div):
    #K回までの切断で全部を長さdiv以下にできるかどうか
    cnt = 0
    for i in range(N):
        cnt += A[i]//div
        if cnt > K:
            return False

    return True

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

    ans = solve(A,N,K)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def f(x):
    return sum((a+x-1)//x - 1 for a in A)

l = 1
r = 10**9+1 
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) <= K:
        r = mid
    else:
        l = mid
print(r)

Submission status: Wrong Answer

Solution code:
#二分探査かぁ…
from math import *
import fractions
import collections
import itertools
import pprint
from collections import deque
from heapq import *
N,K=map(int,input().split())
A=list(map(int,input().split()))
maxnum=10**9+20
minnum=1
while maxnum-minnum>1:
    cnt=0
    piv=(maxnum+minnum)//2
    for i in range(N):
        cnt=cnt+(ceil(A[i]/piv)-1)
    #print(cnt,piv)
    if cnt>K:
        minnum=piv
    else:
        maxnum=piv
    #print(maxnum,minnum)
    #input()
print(min(maxnum,max(A)))

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()
    a.sort(reverse=True)
    upper = 10 ** 9 + 1
    under = 0

    while upper - under > 1:
        middle = (upper + under) // 2

        tk = k
        flg = True
        for ai in a:
            if ai <= middle:
                break

            ta = ai
            tk -= int((ta - middle) / middle)
            if tk < 0:
                flg = False
            break

        if flg:
            upper = middle
        else:
            under = middle

    print(math.ceil(under))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))


INF=10**20
def main():
    N,K=mi()
    A=list(mi())

    A.sort(reverse=True)
    l = 0
    r = A[0]

    while r-l > 1:
        # print("l,r:",l,r)
        mid = (r+l)/2
        
        count = 0

        for i in range(N):
            if mid < A[i]:
                count += math.ceil(A[i]/mid)-1
        
        # print(mid,count)
        if count > K:
            l = mid
        else:
            r = mid
    
    print(math.ceil(l))

    






if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

a.sort()
a.reverse()
total = sum(a)

# 期待値
mn = 1/ (k+1)
a = np.array(a)
b = a

# 割合
ab = a/total

# 少なくとも何回切れるか
a = ab//mn

# 切った後の長さ
f = b/(a+1)

# 大きい順に並べて
f = np.sort(f)[::-1]

# あと何回切れるか
sm = sum(a)
left = int(k - sm)

print(math.ceil(f[left]))

Submission status: Wrong Answer

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

l, r = sum(A)//(N+K), A[-1]
if l == 0: l = 1

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

    cuts = sum([a//m for a in A])

    if cuts <= K:
        r = m
    else:
        l = m

print(r)

Submission status: Wrong Answer

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

for i in range(n):
    a[i] = -math.log2(a[i])
heapq.heapify(a)
for _ in range(k):
    heapq.heappush(a, heapq.heappop(a)+1)

print(a)
print(int(-(-2**(-1*heapq.heappop(a))//1)))

Submission status: Wrong Answer

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

l, r = sum(A)//(N+K), A[-1]
if l == 0: l = 1

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

    cuts = sum([(a-1)//m for a in A])

    if cuts <= K:
        r = m
    else:
        l = m

print(r)

Submission status: Wrong Answer

Solution code:
from math import ceil


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    lower = 1
    upper = 10 ** 9 + 7
    while upper - lower >= 0.5:
        target = (lower + upper) / 2
        now = 0
        for i in range(n):
            now += ceil(a[i] / target) - 1
        if now > k:
            lower = target
        else:
            upper = target
    print(ceil(lower) if k > 0 else a[-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [int(ceil(a/pivot)) for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k

if K >= 1000000:
    for i in range(N):
        h = hiritu[i]
        k = int(ceil(K*h/hirituSum))
        kaisu.append(k)
        K -= k

leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print(ceil(l))

Submission status: Wrong Answer

Solution code:
#二分探査かぁ…
from math import *
import fractions
import collections
import itertools
import pprint
from collections import deque
from heapq import *
N,K=map(int,input().split())
A=list(map(int,input().split()))
maxnum=10**9+20
minnum=1
while maxnum-minnum>1:
    cnt=0
    piv=(maxnum+minnum)//2
    for i in range(N):
        cnt=cnt+ceil(A[i]/piv)-1
    #print(cnt,piv)
    if cnt>K:
        minnum=piv
    else:
        maxnum=piv
    #print(maxnum,minnum)
    #input()
print(maxnum)

Submission status: Wrong Answer

Solution code:
#二分探査かぁ…
from math import *
import fractions
import collections
import itertools
import pprint
from collections import deque
from heapq import *
N,K=map(int,input().split())
A=list(map(int,input().split()))
maxnum=10**9
minnum=1
while maxnum-minnum>1:
    cnt=0
    piv=(maxnum+minnum)//2
    for i in range(N):
        cnt=cnt+ceil(A[i]/piv)-1
    #print(cnt,piv)
    if cnt>K:
        minnum=piv
    else:
        maxnum=piv
    #print(maxnum,minnum)
    #input()
print(maxnum)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    lower = 1
    upper = 10 ** 9 + 7
    while upper - lower >= 1:
        target = (lower + upper) / 2
        now = 0
        for i in range(n):
            now += ceil(a[i] / target) - 1
        if now > k:
            lower = target
        else:
            upper = target
    print(floor(lower) if k > 0 else a[-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [a/pivot for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k
if K >= 1000000:
    for i in range(N):
        h = hiritu[i]
        k = int(ceil(K*h/hirituSum))
        kaisu.append(k)
        K -= k

leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print(ceil(l))

Submission status: Wrong Answer

Solution code:
import math
import bisect
'''
N, K = map(int, input().split())
leng = list(map(int, input().split()))
leng.sort()
cut = [0] * N
# A = [maruta(a, 0) for a in A_tmp]
for a in range(K):
    new_cut = cut.pop() + 1
    new_leng = leng.pop() * (new_cut / (new_cut + 1))
    idx = bisect.bisect_left(leng, new_leng)
    leng.insert(idx, new_leng)
    cut.insert(idx, new_cut)
    # print(new_leng, new_cut)
print(leng)
print(cut)

print(math.ceil(leng[-1]))
'''
N, K = map(int, input().split())
leng = list(map(int, input().split()))
leng.sort()
sum_leng = sum(leng)
# ratio_leng = [sl / sum_leng for sl in leng]
# cut = [K * mul for mul in ratio_leng]
new_leng = []
# for i in range(len(leng)):
while leng:
    last_leng = leng.pop()
    new_cut = math.ceil(K * last_leng / sum_leng)
    sum_leng -= last_leng
    K -= new_cut
    new_leng.append(last_leng / (new_cut + 1))
    # print(new_cut, new_leng[-1], K)
print(math.ceil(max(new_leng)))

Submission status: Wrong Answer

Solution code:
#二分探査かぁ…
from math import *
import fractions
import collections
import itertools
import pprint
from collections import deque
from heapq import *
N,K=map(int,input().split())
A=list(map(int,input().split()))
maxnum=max(A)
minnum=1
while maxnum-minnum>1:
    cnt=0
    piv=(maxnum+minnum)//2
    for i in range(N):
        cnt=cnt+ceil(A[i]/piv)-1
    #print(cnt,piv)
    if cnt>K:
        minnum=piv
    else:
        maxnum=piv
    #print(maxnum,minnum)
    #input()
print(maxnum)

Submission status: Wrong Answer

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

leq,high = 0,1e10
while high-leq > 1:
  l = int((leq+high)/2)
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  print(l,cnt)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()
    a.sort(reverse=True)
    upper = 10 ** 9 + 1
    under = 0

    while upper - under > 0.01:
        middle = (upper + under) / 2

        tk = k
        flg = True
        for ai in a:
            if ai < middle:
                break

            ta = ai
            tk -= int(ta / middle)
            if tk < 0:
                flg = False
                break

        if flg:
            upper = middle
        else:
            under = middle

    print(math.ceil(under))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
M = max(A)
l,r = 1,M
cnt = 0
ans = float('inf')
while l<=r:
    cnt = 0
    mid = (l+r)//2
    for a in A:
        cnt += a//mid
    if cnt <=k:
        ans = min(ans,mid)
        r = mid-1
    else:
        l = mid+1
print(ans)