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 bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if int(ans)==int(mid):
                flag=True
        ans=min(ans, mid)
        right=mid
        
        if flag:
            break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, mid)
        right=mid
        pre=mid
    count+=1
    if count>=10**6:
        break


if ans==float("INF"):
    ans=max(A)
print(ceil(ans))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=sorted(lmp())
ans=10**10
l=1
r=a[-1]
x=l
y=r
while True:
    if x==l and y==r:
        print(r)
        exit()
    m=(l+r)//2
    c=0
    for i in a:
        c+=-(-i//m)-1
    if c>k:
        l=m
    else:
        r=m

Submission status: Wrong Answer

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    th = sum(A) / (K+1)
    print(A)
    print(th)
    print("#####")
    remdiv = K
    results = []
    for a in A:
        if remdiv <= 0:
            results.append(a)
        left = 1
        right = remdiv+1
        while (right - left) > 1:
            mid = left + (right - left) // 2
            if a / mid < th:
                right = mid
            else:
                left = mid
        results.append(a / right)
        remdiv -= (right-1)
    print(remdiv)
    print(results)
    maxr = max(results)
    print(maxr)
    import math
    print(math.ceil(maxr))


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
cut = [1]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]

print(int(max(chip)))

Submission status: Wrong Answer

Solution code:
import heapq
import math

def _heappush_max(heap, item):
  heap.append(item)
  heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
  """Maxheap version of a heappop."""
  lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
  if heap:
    returnitem = heap[0]
    heap[0] = lastelt
    heapq._siftup_max(heap, 0)
    return returnitem
  return lastelt

def main():
  n, k = map(int,input().split())
  li = list(map(int,input().split())) 
  heapq._heapify_max(li)
  for i in range(k):
    x = _heappop_max(li)
    x /= 2
    _heappush_max(li,x)
  ans = math.ceil(_heappop_max(li))
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

from collections import deque
da=deque(a)
db=deque()
for ii in range(k):
  #print(da,db,len(da),len(db))
  if len(da)>0:
    a0=da.popleft()
  else:
    a0=db.popleft()
  #print(da,db)
  if len(db)>0 and db[0]>a0:
    da.append(a0)
    db.popleft()
  else:
    db.append(a0/2)
    db.append(a0/2)
import math
if len(da)>0:
  a0=da.popleft()
else:
  a0=db.popleft()

print(math.ceil(a0))

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

    ans = max(a)
    while upper - under > 0.1:
        middle = (upper + under) / 2

        tmp_max = 0
        tk = k
        flg = True
        for ai in a:

            ta = ai
            cnt = 1
            while ta > middle:
                ta /= 2
                tk -= cnt
                cnt *= 2
                if tk < 0:
                    flg = False
                    break

        if flg:
            upper = middle
        else:
            under = middle

    print(int(under))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def cut(x): #xの丸太を半分に
    global A
    A[x] = A[x]/2
    A = sorted(A)

for p in range(K):
    cut(N-1)

print(math.ceil(A[N-1]))

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
def mul(n):
  return n/a[0]
b=list(map(mul,a))
sum=sum(b)
c=[0]*n
cnt=k
for i in range(n):
  c[i]=int(k*b[i]//sum)
  cnt-=c[i]
  a[i]/=(c[i]+1)

print(math.ceil(a[::-1][cnt]))

Submission status: Wrong Answer

Solution code:
import math
nk = input('').split()
n = int(nk[0])
k = int(nk[1])
alist = list(map(int,input('').split()))

alist.sort()
avg = sum(alist)/(n+k)

#print(alist)
#print(avg)

for i in range(k):
    a = alist.pop(-1)
    if a>avg*3:
        a1=avg
        a2=a-avg
    else:
        a1=a/2
        a2=a/2
    alist.append(a1)
    alist.append(a2)
#    print("{} ->{}/{}".format(a,a1,a2))
    alist.sort()

alist.sort()
#print(alist)
print(math.ceil(alist[-1]))

Submission status: Wrong Answer

Solution code:
import sys
import math

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def cc(al, v_max, k):
	for v in al:
		if v < v_max:
			return True
		k -= -(-v // v_max) - 1
		#pa((k, -(-v // v_max)))
		if k < 0:
			return False
	return True
		

def main():
	#a = int(input())
	n, k = tin()
	#s = input()
	al = lin()
	al.sort(reverse = True)
	#print(al)
	ok = al[0]
	ng = 0.01
	while ok - ng > 0.001:
		mid = (ok + ng)/2
		ii=cc(al, mid, k)
		#pa((mid,ii))
		if ii:
			ok = mid
		else:
			ng = mid
	#pa(ok)
	if ok % 1 > 0:
		return ok+1
	return ok
	iok = int(ok * 1000)
	if iok % 10 >= 5:
		iok += 10 - iok%10
		iok = iok // 10
	else:
		iok = iok // 10
		
	if iok %100 >= 10:
		iok += 100 - iok % 100
	iok = iok // 100
	print(iok)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

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

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

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


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

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

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

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

    return arr


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


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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

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

    divisors.sort()
    return divisors


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

n,k = lr()
a = lr()

def getK(num):
    ret = 0
    for tmp in a:
        while tmp > num:
            tmp = tmp/2
            ret+=1
    return ret

ans = 0
l = 0
r = max(a)
while l <= r:
    mid = l + (r-l) / 2
    if getK(mid) < k:
        r = mid-0.1
    else:
        l = mid+0.1
    if l > r:
        ans = mid
        break
print(math.ceil(ans))

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

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import math

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


ok = A[-1]
ng = 0

#print(math.ceil(40 / 10.0) - 1)

def hantei(p):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / p) - 1
        #print(A[i], 'done', cnt)
    #print('~~~')
    #print(p, cnt, K)
    if(cnt > K):
        #ng
        return 'ng'
    else:
        return 'ok'



def shisya(ans):
    if((ans - ans // 1) >= 0.5):
        return(int(ans//1+1))
    else:
        return(int(ans//1))   



while shisya(ok)-shisya(ng) >= 1:
    if(ok - ng < 3.5 - 3.49999999999999999999999999999999999999):
        break
    mid = (ok+ng)/2
    if(hantei(mid) == 'ng'):
        ng = mid
    else:
        ok = mid
    #print(ok, ng)

print(shisya(ng))

Submission status: Wrong Answer

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

tmp = N+K
sumA = sum(A)
for i in range(1,2*10**5):
    if i*tmp >= sumA:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
from math import ceil

m=1
M=10**9

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

def OK(k):
    if sum([ceil(a/k) for a in A])<=K:
        return True
    else:
        return False

while M-m>1:
    p=(m+M)//2
    if OK(p):
        m=p
    else:
        M=p
print(m)

Submission status: Wrong Answer

Solution code:
from math import ceil
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
l = -1
r = 10**9
while l+1 < r:
    m = (l+r)//2
    if m == 0:
        r = 0
        break
    cnt = 0
    for i in range(n):
        cnt += ceil(a[i]/m)-1
    if cnt <= k: r = m
    else: l = m
print(r)

Submission status: Wrong Answer

Solution code:
rule=input().split()
N=int(rule[0])
K=int(rule[1])
data=input().split()
ans=0
for i in range(len(data)):
    ans+=int(data[i])
import math
print(math.floor(ans/(K+1))+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
n,k = map(int,input().split())
log_list = list(map(float,input().split()))
log_list.sort()
 
cut_count = 0
while cut_count < k:
    max_index = log_list[n-1]
    next_index = log_list[n-2]
    div_count = 2
    while(log_list[n-1] / div_count >= log_list[n-2]):
        div_count+=1
    log_list[n-1] = log_list[n-1] / div_count
    cut_count += div_count - 1
    log_list.sort()
 
print(math.ceil((max(log_list))))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = 0
for i in range(N):
    S += A[i]
vmin = 0
if K == 0:
    print(max(A))
else:
    v = math.ceil(S/(K+1))
    p = max(11,v)
    for ii in range(p-10,p+20):
        c = 0
        if ii == 1:
            for j in range(N):
                a = A[j]
                c += a-1
        else:           
            for jj in range(N):
                a = A[jj]
                c += ((a-1) // ii )
        if c <= K:
            print(ii)
            break

Submission status: Wrong Answer

Solution code:

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>2:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
mid-=1
if mid<=0:
    exit()
while True:
    temp=0
    flag=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: mid+=1
    else:
        flag=1
        break
    if flag: break
print(mid)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

def leng(n, f):
    return int(n/f)

logs = np.array(A)
vleng = np.vectorize(leng)

#めぐる式二分探索
def is_ok(i):
    if sum(vleng(logs, i)) <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, 10 ** 9 + 1))

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

import heapq
n,k = imap()
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(k):
    max = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-max/2))
    heapq.heappush(a, (-1)*(-max/2))
print(ma.ceil(-min(a)))

Submission status: Wrong Answer

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

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

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


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

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

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

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

    return arr


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


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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

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

    divisors.sort()
    return divisors


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

n,k = lr()
a = lr()

def getK(num):
    ret = 0
    for tmp in a:
        while tmp > num:
            tmp = tmp/2
            ret+=1
    return ret

ans = 0
l = 0
r = max(a)
while l <= r:
    mid = l + (r-l) / 2
    if getK(mid) < k:
        r = mid-0.5
    else:
        l = mid+0.5
    if l > r:
        ans = mid
        break
print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = 0
for i in range(n):
    p += a[i]
q = -(-p//(k+1))
m = -1
#print(q)
y = 0
if(k == 0):
    m = max(a)
else:
    for i in range(n):
        if(a[i] > q):
            x = 2
            y += 1
            while((a[i]/x) > q):
                x += 1
                y += 1
            if(m < -(-a[i]//x)):
                m = -(-a[i]//x)
            a[i] = -(-a[i]//x)

print(m)

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,comb
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())

n, k = MAP()
a = sorted(LIST(), reverse=True)
count = 0
ans = a[0]
for i in range(n-1):
    tmp = ( (a[i]+a[i+1]-1)//a[i+1] - 1 ) * (i+1)
    if count + tmp <= k:
        count += tmp
        ans = (max(ans,a[i]) + tmp) // (tmp + 1)
    elif count == k:
        break
    else:
        tmp2 = ( k - count ) // (i+1)
        count = k
        ans = (max(ans,a[i]) + tmp2) // (tmp2 + 1)
        break
if count < k:
    tmp2 = ( k - count ) // n
    ans = (max(ans,a[n-1]) + tmp2) // (tmp2 + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

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

sum_a = sum( a )

devide = [ k * a[ i ] // sum_a for i in range( n ) ]
dev_len = [ a[ i ] / ( devide[ i ] + 1 ) for i in range( n ) ]
k -= sum( devide )
dev_len = list( map( float, dev_len ) )

for _ in range( k ):
    max_i = dev_len.index( max( dev_len ) )
    devide[ max_i ] += 1
    dev_len[ max_i ] = a[ max_i ] / ( devide[ max_i ] + 1 )

print( int( max( dev_len ) + 0.5 ) )

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

if K == 0:
    ans = max(A)
else:
    A.sort(reverse=True)
    
    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)
    
    sum_k = sum(k_list)
    res_cut = KK-sum_k
    
    zero_k = 0
    for i in range(1,N+1):
        if k_list[-i] == 0:
            zero_k +=1
        else:
            break
    
    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(X_list[i])
        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])
        
        ans_kouho.sort(reverse=True)
        ans = ans_kouho[res_cut] + lm
        ans = int(ans+1)
    else:
        ans = int(lm+1)
print(ans)

Submission status: Wrong Answer

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

def check(L):
    return sum(a // L for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if not ok: # 
        lo=m+1
    else:
        answer=m
        hi=m
print(min(max(A), answer))


"""
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo

    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo
"""

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

if K == 0:
    ans = max(A)
else:
    A.sort(reverse=True)
    
    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)
    
    sum_k = sum(k_list)
    res_cut = KK-sum_k
    
    zero_k = 0
    for i in range(1,N+1):
        if k_list[-i] == 0:
            zero_k +=1
        else:
            break
    
    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(X_list[i])
        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])
        
        ans_kouho.sort(reverse=True)
        ans = ans_kouho[res_cut] + lm
        ans = int(ans)+1
    else:
        ans = int(lm+1)
print(ans)

Submission status: Wrong Answer

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

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

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


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

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

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

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

    return arr


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


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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

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

    divisors.sort()
    return divisors


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

n,k = lr()
a = lr()

def getK(num):
    ret = 0
    for tmp in a:
        while tmp > num:
            tmp = tmp/2
            ret+=1
    return ret

ans = 0
l = 0
r = max(a)
while l <= r:
    mid = l + (r-l) / 2
    if getK(mid) < k:
        r = mid
    else:
        l = mid+0.1
    if l > r:
        ans = mid
        break
print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
f=len(a)
d=s/(k+f)
p=0
g=max(a)
while k>0:
  g=max(a)
  p=g//d
  k-=p
  a.remove(g)
k+=p
if k==0:
  print(g)
else:
  print(int(g//(k+1)+1))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if int(ans)==int(mid):
                flag=True
        ans=min(ans, mid)
        right=mid
        
        if flag:
            break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, mid)
        right=mid
        pre=mid
    count+=1
    if count>=10**6:
        break
print(ceil(ans))

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

# print("ab:", ab)
# print("mn:", mn)

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

# print("a:", a)
# print("d:", d)

# 切った後の長さ
# c = d/(a+1)
c = ab/(a+1)
# print("c:",c)

# 大きい順に並べて

c = np.sort(c)[::-1]

# e = c.argsort()[::-1]
# print("argsort:", e)
# print("c:",c)
# あと何回切れるか
sm = sum(a)
left = int(k - sm)

# print("left:", left)
p = c * total
# print(p)

print(math.ceil(p[left]))
# print(c[e[left+1]] * total)


# print(sm, left)

# print(a, mn, total)