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: Accepted

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

def func(l,r):
    if l==r:
        return l
    mid = (l+r)//2
    count = 0
    for i in A:
        count += (i-0.1)//mid
    if count <= K:
        return func(l,mid)
    else:
        return func(mid+1,r)

print(func(1,max(A)))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *A = map(int, read().split())

    ng = 0
    ok = 10 ** 9
    while ok - ng > 1:
        mid = (ok + ng) // 2
        res = 0
        for a in A:
            res += (a + mid - 1) // mid - 1
        if res <= K:
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
ng = -1
ok = max(A) + 1
def test(x):
    if x == 0:
      return False
    cnt = 0
    for a in A:
        if a > x:
            cnt += -(-a//x) - 1
    return cnt <= k

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

Submission status: Accepted

Solution code:
def check(N,target,A,K):
  cnt = 0
  for i in range(N):
    cnt += -(-A[i]//target)-1
  if cnt>K:
    return False
  return True

def solve():
  ans = 0
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  low = 0
  high = 10**9
  mid = (low+high)//2
  while high>low+1:
    if check(N,mid,A,K):
      high = mid
    else:
      low = mid
    mid = (low+high)//2
  ans = high
  return ans
print(solve())

Submission status: Accepted

Solution code:
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def pos(a, x, k):
    res = 0
    for i in a:
        res += (i-1)//x
    return res <= k

for _ in range(int(input()) if not True else 1):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    alpha = 1
    omega = 10**9
    while alpha < omega:
        mid = (alpha+omega) // 2
        if pos(a, mid, k):
            omega = mid
        else:
            alpha = mid+1
    print(omega)

Submission status: Accepted

Solution code:
(N, K) = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

L = 0
H = max(A)

def feasible(M): # M: maximum length    
    S = sum([(a - 1) // M for a in A])
    #print("S = {}, K = {}".format(S, K))
    return S <= K

# assert(not feasible(L))
assert(feasible(H))

while H - L > 1:
    #print(H, L)
    M = (H + L) // 2
    if feasible(M):
        H = M
    else:
        L = M

print(H)

Submission status: Accepted

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

def is_ok(x):
    if x == 0:
        return False
    cnt = 0
    for a in A:
        q, r = divmod(a, x)
        if r == 0:
            cnt += q-1
        else:
            cnt += q
    if cnt <= k:
        return True
    else:
        return False

l = 0
r = 10**18
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        r = c
    else:
        l = c
print(r)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.buffer.readline
n, k = map(int, input().split())
A = list(map(int, input().split()))

# A.sort()




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


ok = 10 ** 9
ng = 0

while ok - ng > 1:
    mid = (ok + ng) // 2
    if hantei(mid) <= k:
        ok = mid
    else:
        ng = mid
    # print(ok, ng)
print(ok)

Submission status: Accepted

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

def is_ok(arg):
  # 条件を満たすかどうか？問題ごとに定義
  # arg以下になるように各々の木をきる。回数を足し合わせて、K以下かどうか判定する
  cnt = 0
  for a in A:
    cnt += ceil(a / arg) - 1
  return cnt <= K

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

ng = 0
ok = 10**9 + 1

ans = meguru_bisect(ng,ok)
print(ceil(ans))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
def case(L):
    result=0
    for x in a:
        result+=(x-1)//L
    return result
possible=0
impossible=max(a)
while impossible-possible>1:
    M=(impossible+possible)//2
    if case(M)>k:
        possible=M
    else:
        impossible=M
print(impossible)

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n,k=map(int,input().split())
A=[int(i) for i in input().split()]

l,r=0,max(A)
cur=0
while cur<100:
	mid=(l+r)/2
	ct=0
	for a in A:
		if a<=mid:
			continue
		else:
			t=int(a/mid)
			if t*mid==a:
				t-=1
		ct+=t
	if ct<=k:
		r=mid
	else:
		l=mid
	cur+=1

ans=int(r)
if ans==r:
	print(ans)
else:
	print(ans+1)

Submission status: Accepted

Solution code:

import math

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

A.sort()
def isPossible(maxL):
    cuts = 0
    for x in A:
        if x > maxL:
            cuts += math.ceil(x / maxL) - 1
    return cuts <= K

lo = 0
hi = max(A)
EPS = 10e-7
while hi - lo > EPS:
    mid = (lo + hi) / 2
    if isPossible(mid):
        hi = mid
    else:
        lo = mid

print(math.ceil(hi))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify

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


def check(x):
    # 最長の丸太をx以下にできるか
    # 任意の丸太をx以下にできるか
    cnt = 0
    for ai in a:
        if ai > x:
            if ai % x == 0:
                cnt += ai // x - 1
            else:
                cnt += ai // x
    # print('check', x, cnt)
    return cnt <= k


lb = 0  # False
ub = max(a)  # True
while ub - lb > 1:
    mid = (ub + lb) // 2
    # print(mid, check(mid))
    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Accepted

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


low=0
high=10**9+1

while low<=high:
    mid=(low+high)//2
    if mid==0:
        print(1)
        exit()

    cnt=0
    for a in A:
        if a<=mid:
            continue
        v=ceil(a/mid)
        cnt+=v-1

    if cnt<=K:
        high=mid-1
    else:
        low=mid+1
print(low)

Submission status: Accepted

Solution code:
def isok(arg):
    count = 0
    for i in range(N):
        count += -(-A[i]//arg)-1
    if count <= K:
        return True
    else:
        return False

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if isok(mid):
            ok = mid
        else:
            ng = mid
    return ok

N,K = map(int,input().split())
A = list(map(int,input().split()))
print(bisect(0,10**9))

Submission status: Accepted

Solution code:
n,k=[int(i) for i in raw_input().split()]
a=[int(i) for i in raw_input().split()]
s=0
for i in a:
    s+=i
val=(s+n+k-1)/(n+k)
for i in a:
    k-=i/val
if(k>=0):
    print val
else:
    k=abs(k)
    l=[]
    for i in a:
        x=i/val
        if(x>0):
            l.append((i+x-1)/x)
    l.sort()
    print l[k-1]

Submission status: Accepted

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

ng = 0
ok = 10**9

while ng < ok-1:
    mid = (ng+ok)//2
    
    count = sum((ai-1)//mid for ai in a)
    if count<=k: ok = mid
    else: ng = mid

print(ok)

Submission status: Accepted

Solution code:
from decimal import Decimal
from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
*A, = map(int, input().split())

tot = sum(A)

ng = 0
ok = 10**9

m = 4

while ng + 1 < ok:
    m = (ng+ok)//2
    c = sum((a-1)//m for a in A)
    if c > K:
        ng = m
    else:
        ok = m
print(ok)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  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

#####MakeDivisors######
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)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,K = IL()
A = IL()

def count(x):
  ret = 0
  for a in A:
    ret += math.ceil(a/x)-1
  return ret

def is_ok(x):
  if count(x)>K:
    return False
  else:
    return True
  
def meguru_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(meguru_bisect(0,10**10))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ma=max(A)
    l=0.0
    r=ma
    if K==0:
        print(ma)
        return

    def hantei(mid):
        cnt=0
        for a in A:
            cnt+=math.ceil(a/mid)-1
        return cnt<=K

    while r-l>1:
        mid=(l+r)//2
        if hantei(mid):
            r=mid
        else:
            l=mid
    mid=(l+r)//2



    print(int(r))

    



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo


@mt
def slv(N, K, A):

    def f(l):
        k = 0
        for a in A:
            k += -(-a//l) - 1
        return 1 if k <= K else 0

    ans = Bisect(f).bisect_left(1, 1, 10**9+1)

    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import ceil

def meguru_bisect(ng, ok):
    """
    初期値のng,okを受け取り, check=>Trueを満たす最大値(最小値)を返す
    条件を満たす最大値を求める場合、初期値は(ng:上限の外, ok:下限の外)   例) 10**9+1, -1
    条件を満たす最小値を求める場合、初期値は(ng:下限の外, ok:上限の外)   例) -1, 10**9+1
    上限の外や下限の外が返ってくる場合は条件を満たす値が範囲内になかったことを示すので、例外処理が必要
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok

def check(x):
    count = 0
    for a in A:
        count += ceil(a / x) - 1
    return count <= k

n, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
ans = meguru_bisect(0, 10**9 + 1)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
def c(x):
    cnt=0
    for i in a:
        cnt += i // x
    return cnt<=k
l, r = 0, max(a)
for i in range(100):
    mid = (l + r) / 2
    if c(mid):
        r = mid
    else:
        l = mid
print(ceil(l))

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, K = NMI()
    A = NLI()
    ng = 0
    ok = 10**10

    for i in range(100):
        mid = (ok + ng) // 2
        if mid == 0:
            break
        tmp = 0
        for a in A:
            if a % mid == 0:
                tmp += a // mid - 1
            else:
                tmp += a // mid
        if tmp <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
*arr, = map(int, input().split())

lo = 1
hi = max(arr) + 1

def can(arr, rem_length, k):
    cnt = 0
    for v in arr:
        cnt += (v - 1) // rem_length
    if cnt <= k:
        return True
    return False


while lo < hi:
    mid = (lo + hi) // 2
    if can(arr, mid, k):
        hi = mid
    else:
        lo = mid + 1


print(lo)

Submission status: Accepted

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

minL = 1
maxL = max(A)

while True:
    if minL >= maxL:
        break
    midL = (minL + maxL) // 2
    cut = 0
    for elem in A:
        cut += elem // midL
        if elem % midL == 0:
            cut -= 1
    if cut <= K:
        maxL = midL
    else:
        minL = midL + 1
print(maxL)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = [int(item) for item in input().split()]
l = 0; r = 1000000001
while r - l > 1:
    mid = (l + r) // 2
    cnt = 0
    for item in a:
        cnt += (item - 1) // mid
    # Can be cut in k times
    if cnt <= k:
        r = mid
    else:
        l = mid

print(l + 1)

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
n,k=NM()
hi=10**9
lo=1
l=L()
def f(mi):
    x=0
    for i in l:
        if i<=mi:
            continue
        x+=(i+mi-1)//mi-1
    if x<=k:
        return True
    return False
while hi>=lo:
    mi=(hi+lo)//2
    if f(mi):
        hi=mi-1
    else:
        lo=mi+1
print(lo)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

n, k = LI()
A = LI()
ok = max(A)
ng = 0
while ok - ng > 1:
    cnt = 0
    mid = (ok + ng) // 2
    for a in A:
        if a % mid == 0:
            cnt += a // mid - 1
        else:
            cnt += a // mid
        if cnt > k:
            ng = mid
            break
    else:
        ok = mid

print(ok)

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

def Binary_Search(N, K, A):
	#初期化
	left = 0
	right = 10 ** 9
	ans = INF
	
	while left <= right:
		mid = (left + right) // 2
		val = 0
		if mid == 0:
			return 1
		for i in range(N):
			val += int((A[i] - 1) // mid)
		if val <= K:
			ans = min(ans, mid)
			right = mid - 1
		else:
			left = mid + 1

	return ans

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	ans = Binary_Search(N, K, A)
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

def num_cut(L):
  result = 0
  for a in A:
    result += a//L
    if a%L == 0:
      result -= 1
  return result

m = 0
M = 10**9

while M-m>1:
  X = (m+M)//2
  if num_cut(X)>K:
    m = X
  else:
    M = X

print(M)

Submission status: Accepted

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

import sys
input=sys.stdin.readline

n,k=map(int,input().split())
arr=list(map(int,input().split()))
l=0
r=max(arr)+1
while r-l!=1:
    persuit=(r+l)//2
    cnt=0
    for val in arr:
        if val<=persuit:
            continue
        if val%persuit==0:
            cnt+=val//persuit-1
        else:
            cnt+=val//persuit
    if cnt<=k:
        r=persuit
    else:
        l=persuit
print(r)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))

l = 0
r = 10**9+3
m = (l+r)//2
while r-l > 1:
    ans = 0
    for i in range(n):
        ans += -((-A[i])//m) - 1
    if ans > k:
        l = m
    else:
        r = m
    m = (l+r)//2
print(m+1)


# Q = []
# from heapq import heappush, heappop

# for i in range(n):
#     heappush(Q, [-A[i], 1])

# print(Q)

# while k > 0:
#     q = heappop(Q)
#     a = -q[0]
#     k -= q[1]
#     heappush(Q, [-a/2, q[1]*2])

# print(Q)

# if k==0:
#     print(max(A))
# else:
#     print(-((-a)//1))


# # D = {}
# I = []

# for i in range(n):
#     a = A[i]
#     D[a] = 0
#     I.append(a)
#     for j in range(40):
#         a/=2
#         D[a] = 0
#         I.append(a)

# for i in range(n):
#     D[A[i]] = 1

# I.sort(reverse=True)
# ind = 0

Submission status: Accepted

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

if k == 0:
    print(max(alst))
    exit()

l = 1
r = max(alst)

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

Submission status: Accepted

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



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

def determine(L):
    if L == 0:
        return False
    ret = 0
    for a in A:
        k = a // L
        if k * L == a:
            k -= 1
        ret += k

    if ret <= K:
        return True

    else:
        return False



L = 0
R = 10 ** 9

while L + 1 < R:
    mid = (L + R) // 2
    if determine(mid):
        R = mid
    else:
        L = mid

print(R)

Submission status: Accepted

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

ok, ng = 10**9+1, 0
while abs(ok-ng) > 1:
    mid = (ok+ng) // 2
    # mid = (ok+ng) / 2
    cnt = 0
    for a in al:
        a_cnt = (a-1)//mid
        cnt += max(0,a_cnt)

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

print(ok)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
now = 0
scale = 2**32
while scale:
  cnt = 0
  tmp = now + scale
  for x in a:
    cnt += (x-1) // tmp
  if cnt > k:
    now = tmp
  #print(tmp,cnt)
  scale //= 2
print(now+1)

Submission status: Accepted

Solution code:
N,K = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#割り当てを考えた後は、n等分するのが最適→にぶたん？
NG = 0
OK = 10**9 + 100
#小数点以下切り上げ→最小となるOKのintを求める
def Maruta(L):#長さLにできるか
    Kaisu = sum([a//L - 1 +  bool(a%L) for a in A])
    return Kaisu<=K

while OK - NG > 1:
    Test = (OK + NG)//2
    if Maruta(Test):
        OK = Test
    else:
        NG = Test
print(OK)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
#(ng,ok]type
#if k==0:print(max(l));exit()
#(ng,ok]type
ok,ng=10**9+1,0
def enough(x):
    return sum( (i//x) for i in l if i>x)<=k
# [ok,ng)type->eraseng,ok=ok,ng
eps=10**(-3)
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if enough(mid):ok=mid
    else:ng=mid
print(ok)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = max(a)
while r - l > 1:
    # min is in (l, r]
    c = (l + r) // 2
    t = 0
    for ai in a:
        t += (ai + c - 1) // c - 1
    if t <= k:
        r = c
    else:
        l = c
print(r)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
ng=0
ok=10**10
while ok-ng>1:
  mid=(ok+ng)//2
  c=0
  for i in range(n):
    c=c+(A[i]+mid-1)//mid
  if c>k+n:
    ng=mid
  else:
    ok=mid
print(ok)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n, k = LI()
    q = []
    a = LI()
    l = 0
    r = max(a)+1
    while l+1 < r:
        m = (l+r) >> 1
        s = sum([math.ceil(i/m) for i in a])-n
        if s <= k:
            r = m
        else:
            l = m
    print(r)
    return

#Solve
if __name__ == "__main__":
    solve()