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:
temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
temparr = input()
import math
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
arr = sorted(arr)
#print(arr)

left = 0 
right = arr[-1] + 1
ans = arr[-1]
while left <= right:
    mid = (left + right) // 2 
    count = 0 
    for i in arr :
        if i <= mid:
            continue 
        else:
            count += math.ceil(i / mid) - 1 
    if count <= k :
        right = mid - 1 
        if mid < ans:
            ans = mid 
    else:
        left = mid + 1 
print(ans)

Submission status: Runtime Error

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
flag = True
num = 0
right = maxA
left = 0
while(flag):
    num = left+math.floor((right-left)*0.5)
    count = 0
    ##print()
    ##print(num)
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
        ##print(math.ceil(A[i]/num)-1)
    if count > K:
        if right-num>1:
            left = num
        elif right-num==1:
            num = right
            flag = False
    elif count < K:
        if num-left>1:
            right = num
        elif num-left==1:
            num = left
            flag = False
    else:
        flag = False

print(num)

Submission status: Runtime Error

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
xma=a[-1]
x=a[-1]//2
xmi=0
xo=-1
while abs(x-xo)>0.01:
  k2=k
  for i in range(n):
      k2-=math.ceil(a[i]/x)-1
  if k2<0:
      xo=x
      xmi=x
      x=(xma+x)/2
  else:
    xo=x
    xma=x
    x=x/2

print(math.ceil(x))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vvl=vector<vl>;
using vs=vector<string>;
using vb=vector<bool>;
using pll=pair<ll,ll>;
using vpll=vector<pll>;
const ll oo=0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll N, K;
vl logs;

bool possible(ll mid) {
	ll cuts_needed = 0;
	FOR(i, 0, N) {
		// logs[i] / (cuts + 1) = res;
		cuts_needed += ceil(logs[i] / double(mid) - 1);
	}
	if (cuts_needed <= K) {
		return true;
	} else {
		return false;
	}
}

int main(){
	cin.sync_with_stdio(0);

	cin >> N >> K;

	logs.resize(N);
	for (ll &l: logs) cin >> l;

	ll low = 0;
	ll hig = 1000000000;

	while (hig - low > 1) {
		ll mid = (low + hig) / 2;
		if (possible(mid)) {
			hig = mid;
		} else {
			low = mid;
		}
	}
	if (possible(low)) {
		cout << low << endl;
	} else {
		cout << hig << endl;
	}
}

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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

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):
    if mm==0:
        mm=1
    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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

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):
    if mm=0:
        mm=1
    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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

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):
    if mm=0:
      mm=1
    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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

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):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

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):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//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) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  t=0
  for i in range(N):
    t+=math.ceil(A[i]/x)-1
  if t<=K:
    return 10
  else:
    return 0
low=0
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+sig)//2
  else:
    low=sig+1
    sig=(high+sig)//2
print(ans)

Submission status: Runtime Error

Solution code:
import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
a=max(A)
l=0
y=copy.copy(a)
while l<=a:
    x=(l+a)//2
    m=sum([A[i]//x for i in range(N)]) # x以下にするための回数
    if m<=K:
        a=x-1
        y=copy.copy(x)
    else:
        l=x+1
print(y)

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):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//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=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:
    if um-lm<5:
        break

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

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=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:
    if um-lm<5:
        break

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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(200):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,max(1,m-10),-1):
    if rf(mi)!=rf(mi-1):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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(200):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,max(1,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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(200):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
#    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import os
import math

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, k = map(int, input().split())
    a_s = list(map(int, input().split()))

    right = 1000000001
    left = 0

    # ループ数に意味はない
    for i in range(100):

        if left + right == 0:
            break

        middle = (left + right) // 2

        # middleより長い木を切る(切るべき回数の合計を取得する)
        cnt = 0
        for a in a_s:
            if a > middle:
                # 4/2 = 2    なら1回切る必要がある
                # 4/3 = 1.33 なら1回切る必要がある
                # 7/3 = 2.33 なら2回切る必要がある
                cnt += math.ceil(a / middle) - 1

        if cnt < k:
            # 最大値を下げる=小さい方に寄せる
            right = middle
        elif cnt > k:
            # 最小値を上げる=大きい方に寄せる
            left = middle
        else:
            # 最大値を下げる=小さい方に寄せる
            right = middle

    print(middle + 1)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
7 9"""
        output = """4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 0
3 4 5"""
        output = """5"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202"""
        output = """292638192"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import os
import math

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, k = map(int, input().split())
    a_s = list(map(int, input().split()))

    right = 1000000001
    left = 0

    # ループ数に意味はない
    for i in range(100):
        middle = (left + right) // 2

        # middleより長い木を切る(切るべき回数の合計を取得する)
        cnt = 0
        for a in a_s:
            if a > middle:
                # 4/2 = 2    なら1回切る必要がある
                # 4/3 = 1.33 なら1回切る必要がある
                # 7/3 = 2.33 なら2回切る必要がある
                cnt += math.ceil(a / middle) - 1

        if cnt < k:
            # 最大値を下げる=小さい方に寄せる
            right = middle
        elif cnt > k:
            # 最小値を上げる=大きい方に寄せる
            left = middle
        else:
            # 最大値を下げる=小さい方に寄せる
            right = middle

    print(middle + 1)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
7 9"""
        output = """4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 0
3 4 5"""
        output = """5"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202"""
        output = """292638192"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

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):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
#    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

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):
#    print(ii,um,lm,m)
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    else:
        um=m-1
        m=(lm+um)//2
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m,m-10,-1):
#    print("mi",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

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)

def nibu(small,big):
    mid = (small+big)//2
#    k_list = [x//mid for x in A2]
    k_list = [x//mid for x in A]
    sum_k = sum(k_list)
    if sum_k <= K: #達成可能 -> 答えはもっと小さい
        return small,mid # 不可能,可能
    else:
        return mid,big # 不可能,可能


if N==1 or K==0:
    ans = A[0]
else:    
#    All_length = sum(A)
#    KK = K+N-1
#    lmin = int(All_length/(KK+1))
    lmin = 0
    
#    A2 = [x for x in A if x > lmin]
    
#    Kper1 = K//len(A2)
    
#    lmax = int(A[0]/(Kper1+1)) + 1
    lmax = A[1]
    
    while lmax - lmin >= 2:
        lmin, lmax = nibu(lmin,lmax)
    
    ans = lmax
    
print(ans)

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):
    if mm==0:
        mm=1
#        return sum(a)
    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):
#    print(ii,m)
    if um-lm<10:
        break
    elif rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
        um=m
        m=(lm+um)//2
    else:
        continue
#        print(m)
#        break

for mi in range(um,lm-1,-1):
#    print("mi:",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break
print(mi)

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):
    if mm==0:
        mm=1
#        return sum(a)
    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):
#    print(ii,m)
    if um-lm<10:
        break
    elif rf(m)>(n+k):
        lm=m
        m=(um+lm)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+um)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
        um=m
        m=(lm+um)//2
    else:
        continue
#        print(m)
#        break

for mi in range(um,lm,-1):
#    print("mi:",mi)
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break
print(mi)

Submission status: Runtime Error

Solution code:
import math
def is_ok(K, N, A, length):
    s = 0
    for i in range(N):
        if A[i] > length:
            s += math.ceil(A[i] / length)-1
    return K >= s


N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
if K == 0:
    print(max(A))
    exit()
ok = max(A)
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(K, N, A, mid):
        ok = mid
    else:
        ng = mid

print(math.ceil(ok))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_max = max(A)
if K == 0:
    print(A_max)
else:
    X = A_max+1//2
    y = (X+1)//2
    while True:
        c = 0
        d = 0
        for i in range(N):
            c += A[i]//X
            d += A[i]//(X+1)
        if d <= K and c > K:
            print(X+1)
            break
        elif d > K:
            X += y
            y = (y+1) // 2
        elif c <= K:
            X -= y
            y = (y+1) // 2

Submission status: Runtime Error

Solution code:
import math
def solve(K, N, A, length):
    s = 0
    for i in range(N):
        if A[i] > length:
            s += int(A[i] / length)
    return K >= s

# 一本ならナイーブには1/2を繰り返すのが最小になりそうだけど5とかだと1/2, (1/2, 1/2)で次4回切らないと中途半端に長いのが残ってしまう
# 複数本なら一番長いのを常に半分に切れば良さそう？
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
ok = A[-1]
ng = A[0]
while abs(ok - ng) > 1:
    mid = (ok + ng) / 2
    if solve(K, N, A, mid):
        ok = mid
    else:
        ng = mid

print(math.ceil(mid))

Submission status: Runtime Error

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

max_length = max(alist)
cur_length = 0

while(max_length - cur_length > 1):
    next_length = (max_length+cur_length)//2

    test_k = 0
    for i in range(n):
        test_k += math.ceil(alist[i]/next_length)-1

    if test_k <= k:
        max_length = next_length
    else:
        cur_length = next_length
        

if test_k > k:
    print(cur_length+1)
else:
    print(cur_length)

Submission status: Runtime Error

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

max = 0
for i in range(n):
    if max < alist[i]:
        max = alist[i]

max_length = max
cur_length = max_length//2

cuts = 0
for i in range(n):
    cuts += math.ceil(alist[i]/cur_length)-1

test_k = cuts
prev_length = 0
while(cur_length != prev_length):

    prev_length = cur_length
    cuts = 0
    if test_k <= k:
        max_length = cur_length
        cur_length = cur_length//2
    else:
        cur_length = (cur_length+max_length)//2
    if cur_length == 0:
        cur_length = 1
    for i in range(n):
        cuts += math.ceil(alist[i]/cur_length)-1
    test_k = cuts

if test_k > k:
    print(cur_length+1)
else:
    print(cur_length)

Submission status: Runtime Error

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

max = 0
for i in range(n):
    if max < alist[i]:
        max = alist[i]

max_length = max

cur_length = max_length//2

cuts = 0
for i in range(n):
    cuts += math.ceil(alist[i]/cur_length)-1

test_k = cuts
prev_length = 0
while(cur_length != prev_length):

    prev_length = cur_length
    cuts = 0
    if test_k <= k:
        max_length = cur_length
        cur_length = cur_length//2
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
    else:
        cur_length = (cur_length+max_length)//2
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
    test_k = cuts

if test_k > k:
    print(cur_length+1)
else:
    print(cur_length)

Submission status: Runtime Error

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

sum = 0
max = 0
for i in range(n):
    cur = alist[i]
    sum += cur
    if max < cur:
        max = cur

max_length = max

cur_length = sum//n

cuts = 0
for i in range(n):
    cuts += math.ceil(alist[i]/cur_length)-1

test_k = cuts
prev_length = 0
while(cur_length != prev_length):

    prev_length = cur_length
    if test_k <= k:
        max_length = cur_length
        cur_length = cur_length//2
        cuts = 0
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
        test_k = cuts
    else:
        cur_length = (cur_length+max_length)//2
        cuts = 0
        for i in range(n):
            cuts += math.ceil(alist[i]/cur_length)-1
        test_k = cuts

print(cur_length+1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def judge(x):
    cnt = 0
    
    for Ai in A:
        cnt += (Ai+x-1)//x-1
    
    return cnt<=K

def binary_search():
    l, r = 0, 10**9+100
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

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

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
    if mm==0:
      mm=1
    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(600):
    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:
n,k = map(int,input().split())
a = list(map(int,input().split()))
target = sum(a)/(n - 1 + k)
new_a = sorted(a, reverse=True)
#print(target,new_a)
tmp = 0
cut = int(new_a[0]/target) - 1
ans = int(new_a[0] / int(new_a[0]/target))
for i in range(1,n):
    if target < new_a[i]:
        cut += int(new_a[i]/target) - 1
        tmp = int(new_a[i] / int(new_a[i]/target))
        if ans < tmp:
            cut += 1
            tmp = int(new_a[i] / (int(new_a[i]/target) + 1))
print(ans)

Submission status: Runtime Error

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

ok = 10 ** 9  # 解が存在する値
ng = -1  # 解が存在しない値


def solve(x):
    """
    一番長いのをx以下にできるか
    → 全部をx以下にするのに切る回数 <= K
    """
    res = 0
    for i in range(N):
        res += (A[i] - 1) // x

    return res <= K


while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
 
N, K = map(int, readline.split())
A = list(map(int, readline().split()))
 
l = 0, r = 10**10
 
def test(m):
  return sum((a + m - 1) // m for a in A) <= K

while l + 1 < r:
  m = (l + r) // 2
  if test(m):
  	r = m
  else:
    l = m
print(r)