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:
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.ceil(ans/(K+1)))

Submission status: Wrong Answer

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

tot=0
for log in a_s:
	tot+= log
table={}

ans= 0


for log2 in a_s:
	test= math.ceil(log2/ ((math.ceil(log2/tot*k))+1))
	if test>ans:
		ans=test
print(ans)

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
for i in range(K):
  x = np.argmax(Logs)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]
print(int(max(chip)))

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.499999999999999):
        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())
from collections import deque
A=deque(map(int,input().split()))
A=sorted(A)
if 90*n<k:
    print(1)
else:
    i=0
    while i!=k:
        a=A.pop()/2
        A+=[a]*2
        A=sorted(A)
        i+=1
    print(int(A.pop()))

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]
while True:
    if l==r-1:
        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:
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:
    for i in range(N):
        a = A[i]
        kk = a/math.ceil(1+a*K/S)
        vmin = max(vmin,kk)
    v = math.ceil(vmin)
    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:
# 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.5
    if l > r:
        ans = mid
        break
print(math.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]
while True:
    print(l,r)
    if l==r-1:
        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:
#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:
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 if A[i]%mid==0 else A[i]//mid+1) 
    if(K<tmp):
        l=mid
    else:
        r=mid

tmp=0
for i in range(len(A)):
    tmp+=(A[i]//l if A[i]%l==0 else A[i]//l+1) 

if(K<=tmp):
    print(r)
    sys.exit(0)
else:
    print(l)
    sys.exit(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
import math

import heapq
from sys import stdin
input = stdin.readline


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

  if K == 0:
    print(max(A))
    return

  def solve(L):
    ncut = 0
    for i in range(N):
      ncut += (math.ceil(A[i]/L) - 1)
      # ncut += math.floor(A[i]/L)
      if ncut > K:
        return False
    return True

  ok = 10**9
  ng = 1
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    bool_ = solve(mid)
    # print(mid, bool_)
    if bool_:
      ok = mid
    else:
      ng = mid

  print(ok)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

Solution code:
from queue import PriorityQueue
N, K = map(int, input().split())
A = list(map(int, input().split()))
pq = PriorityQueue()
for a in A:
    pq.put(-a)
for _ in range(K):
    now = pq.get()
    # print("取り出した値 : ", now)
    a, b = now/2, now/2
    # print("切り出し : ", a, b)
    pq.put(a)
    pq.put(b)
print(int(-pq.get()))

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(ok, ng):
        """
        is_okを定義して下さい
        :param ok: 取りうる最小の値-1
        :param ng: 取りうる最大の値+1
        :return: is_okを満たす最小(もしくは最大)の値
        """
        while abs(ok - ng) > 10 ** -7:
            mid = (ok + ng) / 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def is_ok(x):
        cnt = 0
        for i in range(n):
            if A[i] > x:
                cnt += (A[i] + x - 1) // x - 1

        return cnt <= k

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

    res = meguru_bisect(10 ** 9, -1)
    print(math.ceil(res))


if __name__ == '__main__':
    resolve()

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
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:
        right=mid
        pre=mid

print(ceil(ans))

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)
	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:
## 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.499999999999999):
        break
    mid = (ok+ng)/2
    if(hantei(mid) == 'ng'):
        ng = mid
    else:
        ok = mid
    #print(ok, ng)

print(shisya(ok))

Submission status: Wrong Answer

Solution code:
import sys

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


def is_ok(x):
    num = 0
    for j in range(N):
        num += (A[j] - 1) // x

    if num <= 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(1, 10 ** 9))

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

tmp=0
for i in range(len(A)):
    tmp+=A[i]//l

if(K<=tmp):
    print(r)
    sys.exit(0)
else:
    print(l)
    sys.exit(0)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
if K==0:print(max(A));exit()

left,right=0,10**9+1
while right>left+1:
    cnt=K
    mid=(left+right)//2
    for i in range(N):
        cnt -=A[i]//mid
    if cnt>0:right=mid
    elif cnt<0:left=mid
    elif cnt==0:
        while right>left+1:
            cnt1,cnt2=K,K
            mid=(left+right)//2
            for i in range(N):
                cnt1 -=A[i]//mid
            for i in range(N):
                cnt2 -=A[i]//(mid+1)
            if cnt1==0 and cnt2==0:right=mid
            elif cnt1!=0 and cnt2!=0:left=mid
            elif (cnt1,cnt2)==(-1,0) or (cnt1,cnt2)==(0,-1):
                ans=10**10
                for i in (mid,mid+1):
                    cnt=K
                    for j in range(N):
                        cnt -=A[j]//i
                    if cnt==0:
                        ans=min(ans,i)
                print(ans)
                exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
import math

import heapq
from sys import stdin
input = stdin.readline


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

  if K == 0:
    print(max(A))
    return

  def solve(L):
    ncut = 0
    for i in range(N):
      # ncut += math.ceil(A[i]/L)
      ncut += math.floor(A[i]/L)
      if ncut > K:
        return False
    return True

  ok = 10**9
  ng = 1
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    bool_ = solve(mid)
    # print(mid, bool_)
    if bool_:
      ok = mid
    else:
      ng = mid

  print(ok)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

Solution code:
import heapq
import math
N,K = map(int,input().split())
a = list(map(int,input().split()))
h = math.ceil(sum(a)/(K+N))

if N<K:
    print(h)
else:
    a = list(map(lambda x:x*(-1), a))
    heapq.heapify(a)    
    for i in range(K):
        m = heapq.heappop(a)
        heapq.heappush(a, h) 
        heapq.heappush(a, m -h)
    res =  heapq.heappop(a) * -1
    print(math.ceil(res))

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
ans = 0
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

C = sum(cut)
res = K - C
if res > 0:
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
new = [length[0]]
k = 1

if res == 1:
  print(math.ceil(max(length[0][0], length[1][0])))
  exit()
while k <res:
  if new[0][0] >= length[k][0]:
    cut[new[0][1]] += 1
    new[0][0] = new[0][0]*cut[new[0][1]]/(cut[[new][1]]+1)
    if len(new) > 1:
      new[0][0] < new[1][0]
      new.sort(key = lambda x: x[0], reverse=True)
    res -= 1
  else: 
    cut[length[k][1]] += 1
    length[k][0] = length[k][0]*cut[length[k][1]]/(cut[length[k][1]]+1)
    new.append(length[k])
    new.sort(key = lambda x: x[0], reverse=True)
    k += 1

new.sort(key = lambda x: x[0], reverse=True)

print(math.ceil(new[0][0]))

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n , k = map(int, input().split())
    a = list(map(int, input().split()))
    from heapq import heappop, heappush, heapreplace
    a = [-x for x in a]
    a.sort()
    for i in range(k):
        x = a[0]
        if abs(x) < 1:
            break
        heapreplace(a, x//3)
        heappush(a, x-x//2)
    ans = abs(a[0])
    print(ans)
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
from fractions import Fraction
from sys import exit
import heapq

n,k, *aa = map(Fraction, open(0).read().split())

left = k/2
right = k*2 + 1
mid = k
summ = sum(aa)
score = None
while 1:
    x = [(ceil(mid*a/summ), a) for a in aa]
    prev = score
    score = sum(a[0]-1 for a in x)
    if prev == score:
        break
    if score > k:
        right = mid
        mid = (left + right) / 2
    elif score < k:
        left = mid
        mid = (left + right) / 2
    else:
        values = [ceil(a/v) for v,a in x]
        print(max(values))
        exit()

x = [(-a/c, c, a) for c,a in x]
heapq.heapify(x)

for _ in range(int(k-score)):
    v,c,a = heapq.heappop(x)
    c += 1
    v = -a/c
    heapq.heappush(x, (v,c,a))

print(ceil(-x[0][0]))

Submission status: Wrong Answer

Solution code:
def solution(x):
  p = sum([a[i]//x for i in range(N)])
  return p
def solvance(y,z):
  if z-y <= 1:
    return z
  else:
    w = (y+z)//2
    #print(y,w,z)
    if solution(w) > K:
      return solvance(w,z)
    else:
      return solvance(y,w)

N,K = map(int,input().split())
a = list(map(int,input().split()))
if K == 0:
  print(max(a))
else:
  ansM = sum(a)//K
  ansm = sum(a)//(K+N)
  ans = solvance(ansm,ansM)
  print(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(l)

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.499999999999999):
        break
    mid = (ok+ng)/2
    if(hantei(mid) == 'ng'):
        ng = mid
    else:
        ok = mid
    #print(ok, ng)

print(shisya(ok))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
arr = list(map(int,input().split()))
denominator = sum(arr)

#piece = [K*arr[i]//denominator+1 for i in range(N)]
#value = [arr[i]/piece[i] for i in range(N)]
#print(piece)
import copy
value = copy.deepcopy(arr)
piece = [1 for i in range(N)]
left = K+N-sum(piece)
for i in range(left):
    j = value.index(max(value))
    piece[j] += 1
    value[j] = arr[j]/piece[j]

import math
print(round(max(value)))

Submission status: Wrong Answer

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

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

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

ave = sum(A) // len(A)

cn = 0
hq = []
for a in A:
    cut = a // ave
    heappush(hq, (-a/(cut + 1), cut + 1, a))
    cn += cut
    # 現在の長さ　カット数　元の長さ

if cn > K:
    hq = []
    for a in A:
        heappush(hq, (-a, 1, a))

for _ in range(cn, K):
    _, c, l = hq[0]
    heapreplace(hq, (-l/(c+1), c+1, l))

max_length, _, _ = heappop(hq)
print(ceil(-max_length))

Submission status: Wrong Answer

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

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

ok = 1
ng = max(A)+1

while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    
    cnt = 0
    for a in A:
        y = math.ceil(a/mid)
        cnt += y-1

    if cnt <= K:
        ng = mid
    else:
        ok = mid+1
    

print(ok)

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
    if(K<tmp):
        l=mid
    else:
        r=mid

tmp=0
for i in range(len(A)):
    tmp+=A[i]//l

print(r)
sys.exit(0)

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 ok: # 
        answer=m
        hi=m
    else:
        lo=m+1
for l in range(max(1, answer-10),answer+1):
    if check(l):
        answer = l
print(min(max(A), answer))

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.499999999999999):
        break
    mid = (ok+ng)/2
    if(hantei(mid) == 'ng'):
        ng = mid
    else:
        ok = mid
    print(ok, ng)

print(shisya(ok))

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]
    
    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):
            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:
# -*- coding: utf-8 -*-
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A = A[::-1]

range_dict = defaultdict(list)
max_A = A[0]
div = 2
i = 0
while i < N:
    if A[i] > max_A/div:
        range_dict[div-1].append(A[i])
        i += 1
    else:
        div += 1

range_list = [(key,len(value)) for key,value in range_dict.items()]

def count_cut(range_list, k):
    total = 0
    for key, count in range_list:
        total += int((k-1)/key)*count
    return total

k=1
while count_cut(range_list,k) < K:
    k+=1

if k == 1:
    print(max_A)
else:
    remain_K = K-count_cut(range_list,k-1)
    if remain_K == 0:
        print(int((max_A-1)/(k-1)))
        exit(0)
    else:
        for key,value in range_dict.items():
            if int((k-1)/key)-int((k-2)/key) == 1:
                if remain_K >= len(value):
                    remain_K -= len(value)
                elif remain_K == 0:
                    answer = max((max_A-1)/k, (value[0]-1)/(k-1))
                    print(int(answer)+1)
                    exit(0)
                else:
                    answer = max((max_A-1)/k, (value[remain_K]-1)/(k-1))
                    print(int(answer)+1)
                    exit(0)

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
    if(K<tmp):
        l=mid
    else:
        r=mid

tmp=0
for i in range(len(A)):
    tmp+=A[i]//l

if(K<tmp):
    print(r)
    sys.exit(0)
else:
    print(l)
    sys.exit(0)

Submission status: Wrong Answer

Solution code:
import sys

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

# ここは二分探索で行ける
x = max(A) // 2
y = x

while 10000 < x:
    num = 0
    for j in range(N):
        num += (A[j] - 1) // y

    x = x // 2
    if num <= K:
        y -= x
    else:
        y += x

if x < 10000:
    y = 5001

for i in range(y - 5000, y + 5000):

    num = 0
    for j in range(N):
        num += (A[j] - 1) // i

    if num <= K:
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
N, K, *A = map(int, open(0).read().split())

import heapq
hq = []

for i in A:
  heapq.heappush(hq,-(i*1.0))
#
if K > 0:
  for i in range(K):
    a = heapq.heappop(hq)
    heapq.heappush(hq,(a/2))
    heapq.heappush(hq,(a/2))
#
a = heapq.heappop(hq)
a = -a
if int(a) == a:
  print(int(a))
else:
  print(int(a)+1)
#

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n , k = map(int, input().split())
    a = list(map(int, input().split()))
    from heapq import heappop, heappush, heapreplace
    a = [-x for x in a]
    a.sort()
    for i in range(k):
        x = a[0]
        if abs(x) < 1:
            break
        heapreplace(a, x//3)
        heappush(a, x-x//3)
    ans = abs(a[0])
    print(ans)
    


if __name__ == '__main__':
    main()