Problem:


Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192



Sample input:
2 3
7 9


Sample output:
4

Submission status: Runtime Error

Solution code:
import heapq
from math import ceil

class Fraction():
    ##入力定義
    def __init__(self,Numerator=0,Denominator=1):
        """分数のオブジェクトを生成する.

        Numerator:分子
        Denominator:分母
        """
        self.a=Numerator
        self.b=Denominator

    #表示定義
    def __str__(self):
        if self.b==1:
            return str(self.a)
        else:
            return "{}/{}".format(self.a,self.b)

    #四則演算定義
    def __add__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        return Fraction.__reduce(c)

    def __radd__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        
        return Fraction.__reduce(c)
    
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        return -self+other

    def __mul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __rmul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __floordiv__(self,other):
        if other==Fraction():
            raise ZeroDivisionError
        
        H=self/other
        return H.a//H.b

    def __rfloordiv__(self,other):
        if self==Fraction():
            raise ZeroDivisionError

        H=other/self
        return H.a//H.b
    
    def __truediv__(self,other):
        if other==Fraction():
            raise ZeroDivisionError
        
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return self*Fraction.__inverse(other)

    def __rtruediv__(self,other):
        if self==Fraction():
            raise ZeroDivisionError
        
        if not(isinstance(self,Fraction)):
            self=Fraction.Int_to_Fraction(other)
            
        return Fraction.__inverse(self)*other

    def __pow__(self,other):
        if other==0:
            return 1
        n=abs(other)

        g=1
        k=self
        for i in range(int(math.log(n,2))+1):
            if n%2==1:
                g*=k

            k*=k
            n=n>>1

        if other>0:
            return g
        else:
            return 1/g

    #丸め
    def __floor__(self):
        return self.a//self.b

    def __ceil__(self):
        return (self.a+self.b-1)//self.b
    
    #比較演算子
    def __eq__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a==0
        else:
            return t==0
    
    def __nq(self,other):
        return not(self==other)

    def __lt__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a<0
        else:
            return t<0

    def __le__(self,other):
        return (self<other) or (self==other)

    def __gt__(self,other):
        return -self<-other

    def __ge__(self,other):
        return (other<self) or (self==other)
    
    #その他
    def ToNumber(self):
        return self.a/self.b

    def sign(self):
        s=self.a*self.b
        if s>0:return 1
        elif s==0:return 0
        else:return -1

    def __reduce(self):
        from math import gcd
        g=gcd(self.a,self.b)
        self.a//=g
        self.b//=g

        if self.b<0:
            self.a*=-1
            self.b*=-1
        return Fraction(self.a,self.b)

    def Int_to_Fraction(self):
        if not(isinstance(self,Fraction)):
            return Fraction(self,1)
        else:return self
        
    def __inverse(self):
        if self==Fraction():
            raise ZeroDivisionError
        
        return Fraction.__reduce(Fraction(self.b,self.a))
    
    def __pos__(self):
        return self

    def __neg__(self):
        return Fraction(-self.a,self.b)

    def __abs__(self):
        return max(self,-self)
#=======================================
N,K=map(int,input().split())
A=list(map(lambda x:-Fraction(int(x),1),input().split()))
   
heapq.heapify(A)

while K>0:
    x=-heapq.heappop(A)

    if x<1:
        heapq.heappush(A,-a)
        break
    y=-heapq.heappop(A)
    
    M=min(max(ceil(x.a/y-x.b),1),K)
    x.b+=M
    K-=M
    heapq.heappush(A,-x)
    heapq.heappush(A,-y)

b=-A[0]
b=ceil(b)
print(b)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
s = sum(a)
x = [0]*n
y = 0
for i in range(n):
    y = int(a[i]/s*k)
    x[i] = [i, (a[i]/s*k)%1, y]

x.sort(key= lambda val : val[1],reverse=True)
for i in range(k-y):
    x[i][2] += 1
ans = 0
z = 0
for i in range(n):
    ans = max(ans, a[x[i][0]-1]/(x[i][2]+1))
    z += x[i][2]
print(int(-(-ans//1)))

Submission status: Runtime Error

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
    x = 0
    for a in A:
        y = math.ceil(a/mid)
        cnt += y-1
        x = max(a/y, x)

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

print(math.ceil(x))

Submission status: Runtime Error

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 rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    else:
#        print(m)
        break

for mi in range(m,0,-1):
    if rf(mi)!=(n+k):
        break
print(mi+1)

Submission status: Runtime Error

Solution code:
import math

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

af = [float(a[i]) for i in range(n)]

s = sum(a)

for i in range(n):
    t = round(k * a[i] / s)
    temp = a[i]
    af[i] = a[i] / (t + 1)
    s -= temp + af[i]

print(math.ceil(max(af)))

Submission status: Runtime Error

Solution code:
import math
N, K = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
# 初期配分
sum_of_As = sum(As)
A_cut = []
toK = 0
for a in As:
    n_c = K * a//sum_of_As
    A_cut.append([a/(n_c+1), n_c+1])
    toK += n_c
# print(A_cut)
# 調整
while toK < K:
    # print('more cut')
    A_cut = [a for a in A_cut if a[0] >= 1]
    A_cut = sorted(A_cut, key=lambda x: x[0])
    # print(A_cut)
    A_cut[-1] = [A_cut[-1][0]*A_cut[-1][1]/(A_cut[-1][1] + 1), A_cut[-1][1]+1]
    # print(A_cut[-1])
    toK += 1
A_re = [i for i, _ in A_cut]
print(math.ceil(max(A_re)))

Submission status: Runtime Error

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 rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
#while True:
    print(m,rf(m))
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    else:
        print(m)
        break

for mi in range(m,0,-1):
    if rf(mi)!=(n+k):
        break
print(mi+1)

Submission status: Runtime Error

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
    think = N//res_cut+1
    
    if res_cut > 0:
        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: Runtime Error

Solution code:
nk=input("").split(" ")
n=int(nk[0])
k=int(nk[1])
lia=input("").split(" ")
lisa=[]
for i in lia:
    lisa+=[int(i)*10000]
sa=sum(lisa)
lisf=[]
lisw=[]
t=int(sa/(k+1))
for i in lisa:
    f=i%t
    ffff=(i*(k+1))%sa
    if(ffff==0):
        lisf+=[0]
        lisw+=[int(i*(k+1)/sa)-1]
    else:
        lisf+=[(t-f)/(int(i*(k+1)/sa)+1)]
        lisw+=[int(i*(k+1)/sa)]
print(lisf)
lisf.sort()
s=k-sum(lisw)
kk=int((t-lisf[s])/10000)
if((t-lisf[s])%10000==0):
    print(kk)
else:
    print(kk+1)

Submission status: Runtime Error

Solution code:
nk=input("").split(" ")
n=int(nk[0])
k=int(nk[1])
lia=input("").split(" ")
lisa=[]
for i in lia:
    lisa+=[int(i)*10000]
sa=sum(lisa)
lisf=[]
lisw=[]
t=int(sa/(k+1))
for i in lisa:
    f=i%t
    if(f==0):
        lisf+=[0]
        lisw+=[int(i*(k+1)/sa)-1]
    else:
        lisf+=[(t-f)/(int(i*(k+1)/sa)+1)]
        lisw+=[int(i*(k+1)/sa)]
print(lisf)
lisf.sort()
s=k-sum(lisw)
kk=int((t-lisf[s])/10000)
if((t-lisf[s])%10000==0):
    print(kk)
else:
    print(kk+1)

Submission status: Runtime Error

Solution code:
import math


def mys(a, b):
    for i in range(len(a)):
        if a[i][0] < b[0]:
            return a[:i+1]+[b]+a[i+1:]
    return a.append(b)


N, K = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
# 初期配分
sum_of_As = sum(As)
A_c = []
toK = 0
for a in As:
    n_c = K * a//sum_of_As
    A_c.append([a/(n_c+1), n_c+1])
    toK += n_c
# print(A_c)
# 調整
A_c = sorted(A_c, key=lambda x: x[0])
while toK < K:
    A_c = [a for a in A_c if a[0] >= 1]
    # print('more cut')
    # print(A_c)
    A_c = mys(A_c[:-1], [A_c[-1][0]*A_c[-1][1]/(A_c[-1][1]+1), A_c[-1][1]+1])
    # print(A_c[-1])
    toK += 1
A_re = [i for i, _ in A_c]
print(math.ceil(max(A_re)))

Submission status: Runtime Error

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

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

t = sum(A) / K
a = [None] * len(A)
for i in A:
    k = max(ceil(i / t), 1)
    a.append((-i / k, i, k))

heapify(a)
for _ in range(K):
    i, j, k = heappop(a)
    k += 1
    i = -(j / k)
    heappush(a, (i, j, k))
print(ceil(heappop(a)[0] * -1))

Submission status: Runtime Error

Solution code:
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def isOK(i, A, K):
    return K >= sum((a-1)//i for a in A)

def b_serach(A, K):
    ng = -1
    ok = 10**9+1

    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if isOK(mid, A, K):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = mi()
    A = list(mi())
    print(b_serach(A, K))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[16]:


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


# In[23]:


max(A)
cnt


# In[41]:


cnt = 0
low = 0
high = max(A)
ans = max(A)
old = int(high)
mycount = 0
while low < high:
    mid = (high+low)/2
    cnt = sum([(x-0.001)//mid for x in A])
    if cnt <= K:
        high = mid
        ans = min(ans, int(-(-mid//1)))
    else:
        low = mid
    if int(mid) == old:
        mycount += 1
    if mycount == 100:
        break
    old = int(mid)
print(ans)


# In[ ]:

Submission status: Runtime Error

Solution code:
import heapq, math, sys

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
maxA = A[0]
pre = -1
while len(A) != pre:
    if len(A) == 0:
        print(math.ceil(maxA))
        sys.exit()
    pre = len(A)
    meanA = math.ceil(sum(A)/(len(A)+K))
    for i, a in enumerate(A):
        if a <= meanA:
            A = A[:i]
            break


cuts = [0]*(i+1)
meanA = math.ceil(sum(A)/(len(A)+K))
for i, a in enumerate(A):
    cut_at_least = (a//meanA - 1)
    cuts[i] = cut_at_least
    K -= cut_at_least
hq = [(-a/(cut+1), i) for i, (a, cut) in enumerate(zip(A, cuts))]
heapq.heapify(hq)
for k in range(K):
    l, i = heapq.heappop(hq)
    cuts[i] += 1
    if k == 0:
        heapq.heappush(hq, (-A[i]/(cuts[i]+1), i))
l, i = heapq.heappop(hq)
print(math.ceil(-l))

Submission status: Runtime Error

Solution code:
import math

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

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

for i in range(n):
    t = round(k * a[i] / s)
    temp = a[i]
    a[i] = math.ceil(a[i] / (t + 1))
    s -= temp + a[i]

print(max(a))

Submission status: Runtime Error

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

#めぐる式二分探索
#indexが条件を満たすか判定
def isOK(mid, A):
  count = 0
  for i in range(N):
    if A[i] > mid:
      xx = A[i] / mid
      if xx % 1 != 0:
        xx += 1
      count += int(xx - 1)
      
  #print("c", count)
  if count > K:
    return False
  else:
    return True
  
#にぶたん
#A : 配列
def binary_search(A):
  N = 10 ** 9
  ng = -1
  ok = N
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    #print(ng, ok, mid)
    if isOK(mid, A):
      ok = mid
    else:
      ng = mid
  return ok
  
#a = [1, 14, 32, 51, 51, 51, 243, 419, 750, 910]

print(binary_search(A))

Submission status: Runtime Error

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().strip().split()))

A.sort()
if K == 0:
    print(A[-1])
else:
    ans = 10**9
    l = 0
    r = 10**9
    while l < r:
        # t以下の長さにするのに必要な切る回数
        t = (l + r) // 2
        # print(t)
        n = K
        for a in A:
            n -= (a - 1) // t
            if n < 0:
                break
        if n >= 0:
            ans = min(ans, t)
        if n >= 0:
            r = t
        else:
            l = t + 1

    print(ans)

Submission status: Runtime Error

Solution code:
mport math
def check(lis,k,mid):
	for i in lis:
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)/2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-0.000001
	else:
		a=mid+0.000001
print(int(math.ceil(ans)))

Submission status: Runtime Error

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

low=0
high=max(A)
X=max(A)
while low<=high:
  mid=(low+high)//2
  cnt = 0
  for i in range(N):
      cnt += A[i]//mid
  if K<cnt:
    low=mid+1
  else:
    X=min(X,mid)
    high=mid-1
print(X)

Submission status: Runtime Error

Solution code:
nk=input("").split(" ")
n=int(nk[0])
k=int(nk[1])
lia=input("").split(" ")
lisa=[]
for i in lia:
    lisa+=[int(i)*10000]
sa=sum(lisa)
lisf=[]
lisw=[]
t=int(sa/(k+1))
for i in lisa:
    f=i%t
    if(f==0):
        lisf+=[0]
        lisw+=[int(i/t)-1]
    else:
        lisf+=[(t-f)/(int(i/t)+1)]
        lisw+=[int(i/t)]
    
lisf.sort()
s=k-sum(lisw)
kk=int((t-lisf[s])/10000)
if((t-lisf[s])%10000==0):
    print(kk)
else:
    print(kk+1)

Submission status: Runtime Error

Solution code:
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
a=[i*100 for i in a]
# Binary Search
def ok(x):
    c=0
    for i in a:
      c+=0--i//x
    return c<=n+k
l,r=1,10**11+1
while r-l>1:
  m=l+r>>1
  if ok(m): r=m
  else: l=m
t=0--r//100
print(t-ok(t-1))

Submission status: Runtime Error

Solution code:
import heapq
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
hq=[]
for i in A:
    heapq.heappush(hq,-i)
while K>0:
    t1=heapq.heappop(hq)
    t2=heapq.heappop(hq)
    if t1==t2 or K<3:
        heapq.heappush(hq,t1/2)
        heapq.heappush(hq,t1/2)
        heapq.heappush(hq,t2)
        K-=1
    else:
        heapq.heappush(hq,t1/3)
        heapq.heappush(hq,t1/3)
        heapq.heappush(hq,t1/3)
        heapq.heappush(hq,t2)
        K-=2
print(math.ceil(-heapq.heappop(hq)))

Submission status: Runtime Error

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

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

a = [(-i, i, 1) for i in A]
heapify(a)
while K != 0:
    i, j, k = heappop(a)
    #print(i, j, k)
    t = -a[0][0]
    nk = ceil(j / t)
    t = max(min(nk - k, K), 1)
    K -= t
    k += t
    i = -(j / k)
    heappush(a, (i, j, k))
    #print(i, j, k)
print(ceil(heappop(a)[0] * -1))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
alist=list(map(int,input().split()))
#print(alist)

def num_cut(x):
  ret=0
  for a in alist:
    ret+=-(-(a-x)//x)
  return ret

#for i in range(1,max(alist)):
#  print(i,num_cut(i))

l=1
r=max(alist)+1
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  
  if num_cut(mid-1)>K and num_cut(mid)<=K:
    print(mid)
    break
  elif num_cut(mid)<=K:
    r=mid
  else:
    l=mid

Submission status: Runtime Error

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

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

a = [(-i, i, 1) for i in A]
heapify(a)
while K != 0:
    i, j, k = heappop(a)
    #print(i, j, k)
    t = -a[0][0]
    nk = ceil(j / t)
    t = min(nk - k, K)
    K -= t
    k += t
    i = -(j / k)
    heappush(a, (i, j, k))
    #print(i, j, k)
print(ceil(heappop(a)[0] * -1))

Submission status: Runtime Error

Solution code:
import heapq
N,K=map(int,input().split())
A=list(map(int,input().split()))
hq=[]
for i in A:
    heapq.heappush(hq,-i)
while K>0:
    t1=heapq.heappop(hq)
    t2=heapq.heappop(hq)
    if t1==t2 or K<3:
        heapq.heappush(hq,t1/2)
        heapq.heappush(hq,t1/2)
        heapq.heappush(hq,t2)
        K-=1
    else:
        heapq.heappush(hq,t1/3)
        heapq.heappush(hq,t1/3)
        heapq.heappush(hq,t1/3)
        heapq.heappush(hq,t2)
        K-=2
print(int(-(heapq.heappop(hq)//1)))

Submission status: Runtime Error

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

low=0
high=max(A)
X=max(A)
while low<=high:
  mid=(low+high)//2
  cnt = 0
  for i in range(N):
      cnt += A[i]//mid
  if K<cnt:
    low=mid+1
  else:
    X=mid
    high=mid-1
print(X)

Submission status: Runtime Error

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
for i in range(N):
    a = A[i]
    kk = a/math.ceil(1+a*K/S)
    vmin = max(vmin,kk)
v = math.floor(vmin)
p = max(0,v-2)
for i in range(p,v+4):
    c = 0
    if i == 1:
        for j in range(N):
            a = A[j]
            c += a-1
    else:           
        for jj in range(N):
            a = A[jj]
            c += (a-1) // i 
    if c <= K:
        print(i)
        break

Submission status: Runtime Error

Solution code:
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
a=[i*100 for i in a]
# Binary Search
def ok(x):
    c=0
    for i in a:
      c+=0--i//x
    return c<=n+k
l,r=0,10**11+1
while r-l>1:
  m=l+r>>1
  if ok(m): r=m
  else: l=m
t=0--r//100
print(t-ok(t-1))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]
    A = kwargs["A"]
    A = collections.deque(sorted(A, reverse=True))
    T = [collections.deque() for i in range(k)]
    if len(T) > 0:
        T[0] = A
    else:
        T = [A]

    for i in range(k):
        maxlog = 0
        for j in range(len(T)):
            if len(T[j]) > 0:
                if maxlog < T[j][0]:
                    maxlogrow = j
                    maxlog = T[j][0]
        new = T[maxlogrow].popleft() * (maxlogrow + 1) / (maxlogrow + 2)
        T[maxlogrow + 1].append(new)

    res = 0
    for j in range(len(T)):
        if len(T[j]) > 0:
            if res < T[j][0]:
                res = T[j][0]
    res = math.ceil(res)
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]
    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Runtime Error

Solution code:
import math

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

s = sum(a)

for i in range(n):
    t = round(k * a[i] / s)
    temp = a[i]
    a[i] = math.ceil(a[i] / (t + 1))
    s -= temp + a[i]

print(max(a))

Submission status: Runtime Error

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

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

a = [(-i, i, 1) for i in A]
heapify(a)
while K != 0:
    i, j, k = heappop(a)
    #print(i, j, k)
    t = -a[0][0]
    nk = ceil(j / t)
    t = min(nk - k, K)
    K -= t
    k = nk
    i = -(j / k)
    heappush(a, (i, j, k))
    #print(i, j, k)
print(ceil(heappop(a)[0] * -1))

Submission status: Runtime Error

Solution code:
import sys
N,K=map(int,input().split())
alist=list(map(int,input().split()))
#print(alist)

memo={}
def num_cut(x):
  if x in memo:
    return memo[x]
  
  ret=0
  for a in alist:
    ret+=-(-(a-x)//x)
    
  memo[x]=ret
  return ret

#for i in range(1,max(alist)):
#  print(i,num_cut(i))

l=1
r=max(alist)+1
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  
  if num_cut(mid-1)>K and num_cut(mid)<=K:
    print(mid)
    break
  elif num_cut(mid)<=K:
    r=mid
  else:
    l=mid

Submission status: Runtime Error

Solution code:
#!/usr/bin/env pypy3

import math

def num_cuts(A, ml):
	if ml == 0:
		while True:
			continue
			
	ret = 0
	for a in A:
		ret += (math.ceil(a / ml) - 1)
	return ret

def ok(A, ml):
	return num_cuts(A, ml) <= K

def ans(A, K):

	low = 0.5
	high = max(A)+1

	assert(not(ok(A, low)))
	assert(ok(A, high))

	while (high - low) > 0.1:
		mid = (low + high) / 2
		if ok(A, mid):
			high = mid
		else:
			low = mid

	low = max(1, math.floor(low) - 5)

	for i in range(100):
		p = low + i/3
		q = low + (i+1) / 3

		if not(ok(A, p)) and ok(A, q):
			return math.ceil(q)


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

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

print(ans(A, K))

Submission status: Runtime Error

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)

All_length = sum(A)
KK = K+N-1
lm = All_length/KK

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:
    ans_kouho = []
    for i in range(-zero_k,0):
        ans_kouho.append(X_list[i])
    for i in range(res_cut):
        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: Runtime Error

Solution code:
import heapq
from math import ceil

class Fraction():
    ##入力定義
    def __init__(self,Numerator=0,Denominator=1):
        """分数のオブジェクトを生成する.

        Numerator:分子
        Denominator:分母
        """
        self.a=Numerator
        self.b=Denominator

    #表示定義
    def __str__(self):
        if self.b==1:
            return str(self.a)
        else:
            return "{}/{}".format(self.a,self.b)

    #四則演算定義
    def __add__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        return Fraction.__reduce(c)

    def __radd__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        
        return Fraction.__reduce(c)
    
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        return -self+other

    def __mul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __rmul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __floordiv__(self,other):
        if other==Fraction():
            raise ZeroDivisionError
        
        H=self/other
        return H.a//H.b

    def __rfloordiv__(self,other):
        if self==Fraction():
            raise ZeroDivisionError

        H=other/self
        return H.a//H.b
    
    def __truediv__(self,other):
        if other==Fraction():
            raise ZeroDivisionError
        
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return self*Fraction.__inverse(other)

    def __rtruediv__(self,other):
        if self==Fraction():
            raise ZeroDivisionError
        
        if not(isinstance(self,Fraction)):
            self=Fraction.Int_to_Fraction(other)
            
        return Fraction.__inverse(self)*other

    def __pow__(self,other):
        if other==0:
            return 1
        n=abs(other)

        g=1
        k=self
        for i in range(int(math.log(n,2))+1):
            if n%2==1:
                g*=k

            k*=k
            n=n>>1

        if other>0:
            return g
        else:
            return 1/g

    #丸め
    def __floor__(self):
        return self.a//self.b

    def __ceil__(self):
        return (self.a+self.b-1)//self.b
    
    #比較演算子
    def __eq__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a==0
        else:
            return t==0
    
    def __nq(self,other):
        return not(self==other)

    def __lt__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a<0
        else:
            return t<0

    def __le__(self,other):
        return (self<other) or (self==other)

    def __gt__(self,other):
        return -self<-other

    def __ge__(self,other):
        return (other<self) or (self==other)
    
    #その他
    def ToNumber(self):
        return self.a/self.b

    def sign(self):
        s=self.a*self.b
        if s>0:return 1
        elif s==0:return 0
        else:return -1

    def __reduce(self):
        from math import gcd
        g=gcd(self.a,self.b)
        self.a//=g
        self.b//=g

        if self.b<0:
            self.a*=-1
            self.b*=-1
        return Fraction(self.a,self.b)

    def Int_to_Fraction(self):
        if not(isinstance(self,Fraction)):
            return Fraction(self,1)
        else:return self
        
    def __inverse(self):
        if self==Fraction():
            raise ZeroDivisionError
        
        return Fraction.__reduce(Fraction(self.b,self.a))
    
    def __pos__(self):
        return self

    def __neg__(self):
        return Fraction(-self.a,self.b)

    def __abs__(self):
        return max(self,-self)
#=======================================
N,K=map(int,input().split())
A=list(map(lambda x:-Fraction(int(x),1),input().split()))
   
heapq.heapify(A)
for i in range(K):
    x=-heapq.heappop(A)

    if x<1:
        heapq.heappush(A,-a)
        break

    x.b+=1
    heapq.heappush(A,-x)

b=-heapq.heappop(A)
b=ceil(b)
print(b)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env pypy3

import math

def num_cuts(A, ml):
	ret = 0
	for a in A:
		ret += (math.ceil(a / ml) - 1)
	return ret

def ok(A, ml):
	return num_cuts(A, ml) <= K

def ans(A, K):

	low = 0.5
	high = max(A)+1

	assert(not(ok(A, low)))
	assert(ok(A, high))

	while (high - low) > 0.1:
		mid = (low + high) / 2
		if ok(A, mid):
			high = mid
		else:
			low = mid

	low = max(1, math.floor(low) - 5)

	for i in range(100):
		p = low + i/3
		q = low + (i+1) / 3

		if not(ok(A, p)) and ok(A, q):
			return math.ceil(q)


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

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

print(ans(A, K))