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

Solution (Python):
import sys
import heapq

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    def isOK(mid):
        cnt = 0
        for i in range(N):
            if A[i] > mid:
                cnt += -(-A[i] // mid) - 1
                if cnt > K:
                    return False
        return True

    ok = max(A)
    ng = 0

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

    print(ok)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math


def main():
    N, K = map(int, sys.stdin.readline().rstrip().split())
    A = [int(x) for x in sys.stdin.readline().rstrip().split()]

    high = max(A) + 1  
    low = 0  

    while high - low > 1:
        x = (high - low) // 2 + low

        cnt = 0
        for a in A:
            cnt += math.ceil(a/x) - 1

        if cnt <= K:  
            high = x
        else:
            low = x

    print(high)


main()

Solution (Python):
import sys
from io import StringIO
import unittest
import os
import math


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

        if middle == 0:
            break

        
        cnt = 0
        for a in a_s:
            if a > middle:
                
                
                
                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)

    
    def test_1original_1(self):
        test_input = """2 4
2 3"""
        output = """1"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

Solution (Python):
import math
N, K = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()])




def check(x):
    if x == 0:
        print(1)
        exit()
    cnt = sum(0 - (-a) // x for a in A) - N
    return cnt <= K


lb = -1
rb = 10**9 + 1

while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(mid):
        rb = mid
    else:
        lb = mid
ans = lb
d = 0
for a in A:
    if a % ans:
        d = 1
        break
ans += d
print(ans)

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


def is_ok(arg):
    
    cut = 0
    for a in A:
        cut += (a + arg - 1)//arg - 1
    return cut <= 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

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

Solution (Python):
from math import ceil
import sys
input = sys.stdin.readline

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

    l = 0
    r = 10**10

    while (r-l) > 1:
        x = (l+r) // 2

        c = 0

        for a in A:
            c += ceil(a / x)

        if c-N <= K: r = x
        else: l = x

    c = 0

    for a in A:
        c += ceil(a / r)

    if c-N <= K: print(r)
    else: print(l)

if __name__ == '__main__':
    main()

Solution (Python):









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

A.sort(reverse=True)

def nibu(small,big,KK,AA):
    mid = (small+big)//2
    k_list = [(x-1)//mid for x in AA]
    sum_k = sum(k_list)
    if sum_k <= KK: 
        return small,mid 
    else:
        return mid,big 


if K==0:
    ans = A[0]
else:    
    lmin = 0
    lmax = A[0]
    
    while lmax - lmin >= 2:
        lmin, lmax = nibu(lmin,lmax,K,A)
    
    ans = lmax
    
print(ans)

Solution (Python):

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

def f(x):
    cnt = 0
    for i in a:
        cnt += (i-1) // x
        if cnt > k:
            return False
    return True
            
ok = 10**9
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Solution (Python):
import math

def f(n):
    x = 0
    for ai in a:
        x += math.ceil(ai/n)-1
    return x <= k

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

n,k = map(int,input().split())
a = list(map(int,input().split()))
print(solve(0,max(a)))

Solution (Python):
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 = 0
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))

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
s = sum(a)
x = [0]*n
t = 0
for i in range(n):
    y = int(a[i]/s * k)
    x[i] = [i, a[i], y, a[i]/(y+1)]
    t += y
x.sort(key= lambda val : val[3],reverse=True)
for i in range(k-t):
    x[i][2] += 1
ans = 0
for i in range(n):
    ans = max(ans, x[i][1]/(x[i][2]+1))
print(int(-(-ans//1)))

Solution (Python):

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


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


ok = 10 ** 10
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid


print(ok)

Solution (Python):


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)

Solution (Python):
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
        

print(max_length)

Solution (Python):
def resolve():
    import math
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    r = max(a)
    l = 0
    def cuttimes(p, cutter):
        return math.ceil(p/cutter)-1

    while r-l > 1:
        mid = (r+l)//2
        cut = 0
        for i in range(n):
            cut += cuttimes(a[i], mid)

        if cut <= k:
            r = mid
        else:
            l = mid
    print(r)

resolve()

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

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

def possible(A, K, target):
    count = 0

    for a in A:
        count += ceil(a / target) - 1
    return count <= K

left = 1
right = max(A)

while left < right:
    mid = (left + right) // 2
    if possible(A, K, mid):
        right = mid
    else:
        left = mid + 1

print(right)

Solution (Python):
import math

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

floor = 0
ceil = max(a)


def cut(long, logs):
    cnt = 0
    for i in logs:
        cnt += math.ceil(i / long) - 1
    return cnt


while ceil - floor > 1:
    L = (ceil + floor)//2
    num = cut(L, a)
    if num <= k:
        ceil = L
    else:
        floor = L

print(ceil)

Solution (Python):
import sys
from math import ceil, floor

def cut_logs(x, a):
    return sum(ceil(ai / x) - 1 for ai in a)


def resolve(in_):
    n, k = map(int, next(in_).split())
    logs = tuple(map(int, next(in_).split()))  
    assert n == len(logs)
    max_logs = max(logs)

    lb = 0
    ub = max_logs
    while ub - lb > 1:
        mid = (ub + lb) // 2
        v = cut_logs(mid, logs)
        
        if v <= k:
            ub = mid
        else:
            lb = mid
    

    return ub


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
n, k = map(int, input().split())
aes = list(map(int, input().split()))

bottom, top = 0, max(aes)

def ok(l):
  cnt = 0
  for a in aes:
    if a % l == 0:
      cnt += a // l - 1
    else:
      cnt += a // l
  return cnt <= k

while top - bottom > 1:
  mid = (bottom + top) // 2
  if ok(mid):
    top = mid
  else:
    bottom = mid

print(top)

Solution (Python):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n , k = map(int, input().split())
    a = list(map(int, input().split()))
    
    def check(m):
        cnt = 0
        for x in a:
            cnt += (x-1)//m
        return cnt <= k
        
    l, r = 0, max(a)
    while r-l > 1:
        m = (r+l)//2
        if check(m): r = m
        else: l = m
    print(r)

    


if __name__ == '__main__':
    main()

Solution (Python):
N,K = map(int, input().split())
A = list(map(int, input().split()))
    
l,r = 0, max(A)
while r-l>1:
  mid = (l+r)//2
  cnt = 0
  for i in range(N):
    if A[i]%mid!=0:
      cnt+= A[i]//mid
    else:
      cnt += A[i]//mid - 1
            
  if cnt <= K:
    r = mid
  else:
    l = mid
print(r)

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

right=max(a)
left=0
def logs(a, n, x):
    sm=0
    for i in range(n):
        sm+=(a[i]-1)//x
    if sm<=k:
        return True
    else:
        return False

def binary_search(left, right):
    while right - left > 1:
        center=(left+right)//2
        if logs(a, n, center):
            right=center
        else:
            left=center
    
    return right
        
print(binary_search(left, right))

Solution (Python):






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





low = 0
high = max(A)
def ok(x):
    cnt = 0
    for a in A:
        cnt += (a//x)
        if a%x == 0:
            cnt -= 1
    return cnt <= K
 
while high-low > 1:
    mid = (high+low)//2
    if ok(mid):
        high = mid
    else:
        low = mid
print(high)

Solution (Python):
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 = 1, 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())

Solution (Python):

def resolve():
    def is_ok(mid):
        cnt = 0
        for a in A:
            cnt += (a-1)//mid
        return cnt <= K

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

    ok = max(A)
    ng = 0
    while ok - ng > 1:
        mid = (ok+ng)//2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == "__main__":
    resolve()

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


bottom, top = 0, max(a)


while top - bottom > 1:
    mid = (top+bottom) // 2
    cnt = 0
    for i in a:
        cnt += i//mid
        if i%mid == 0:
            cnt -= 1
    if cnt <= k:
        top = mid
    else:
        bottom = mid

print(top)

Solution (Python):
n, k, *aa = map(int, open(0).read().split())

imp = 0
psbl = 10**9

while psbl - imp > 1:
    mid = (psbl + imp) // 2
    cost = sum(0--a//mid - 1 for a in aa)
    if cost <= k:
        psbl = mid
    else:
        imp = mid

print(psbl)

Solution (Python):
n,k=list(map(int,input().split()))
m=list(map(int,input().split()))
import math
def pos(h):
    p=0
    for i in range(n):
        p+=math.ceil(m[i]/h)-1
    return bool(p<=k)
l,r=1,max(m)
while l<r:
    mid=(l+r)//2
    if pos(mid):
        r=mid
    else:
        l=mid+1
print(l)

Solution (Python):



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

def cnt(x):
  ret = 0
  for ai in a:
    ret += (ai+(x-1))//x - 1
  return ret

ok, ng = a[-1], 0
while ok - ng > 1:
  nw = (ok + ng) // 2
  if cnt(nw)<=k:
    ok = nw
  else:
    ng = nw

print(ok)

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

l = 0
r = 10**9+1

def ok(x):
    cnt = 0
    for b in a:
        cnt += (b//x)
        if b%x == 0:
            cnt -= 1
    return cnt <= k

while r-l > 1:
    md = (l+r)//2
    if ok(md):
        r = md
    else:
        l = md
print(r)

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


def ok(min_l):  
    cnt = 0
    for L in a:

        
        cnt += L // min_l
        
        if L % min_l != 0:
            cnt += 1

        
        cnt -= 1
    return cnt <= k





left = 0
right = max(a)

while right - left > 1:
    mid = (left + right) // 2
    if ok(mid):
        right = mid
    else:
        left = mid

print(right)

Solution (Python):
N,K=map(int,input().split())
A=[int(i) for i in input().split()]






low=0
high=max(A)+1


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

Solution (Python):



def solve(k, ls):
    n = len(ls)
    i0 = 1
    i1 = max(ls)
    i = (i0 + i1) // 2
    while i0 < i1:
        m = 0
        for a in ls:
            m += (a // i) - int(a % i == 0)
        if m <= k:
            i1 = i
            i = (i0 + i1) // 2
        else:
            i0 = i + 1
            i = (i0 + i1) // 2
    return i


def main(istr, ostr):
    n, k = list(map(int, istr.readline().strip().split()))
    ls = list(map(int, istr.readline().strip().split()))
    result = solve(k, ls)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

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

ok = 10 ** 9  
ng = 0  


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)

Solution (Python):
import math

def cut_num(length,max_length):
    return math.ceil(length/max_length)-1

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

l = 1
r = 10**9

while l<r:
    mid = (l+r)//2
    count = 0
    for i in range(n):
        count += cut_num(a[i],mid)
    if count > k:
        l = mid+1
    else:
        r = mid
print(l)

Solution (Python):

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

def is_ok(X):
    return sum([-(-n // X) - 1 for n in A]) <= K

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, max(A)+1))

Solution (Python):

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

def is_ok(X):
    ret = 0
    for log in A:
        ret += -(-log//X) - 1
    return ret <= 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

print(meguru_bisect(0, max(A)+1))

Solution (Python):

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

def is_ok(X):
    ret = 0
    for log in A:
        ret += -(-log//X) - 1
    return ret <= 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

print(meguru_bisect(0, max(A)+1))

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

def check(l):
    cnt = 0
    for _ in a:
        cnt += _ // l
        if _ % l != 0:
            cnt += 1
        cnt -= 1
    if cnt <= k: return True
    else : return False

"""
left: ng
right: ok
"""
def binary(ng, ok):
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if check(mid): ok = mid
        else: ng = mid
    return ok

print(binary(0, max(a)))

Solution (Python):
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=10**10
ng=1
for i in range(40):
    chk=(ok+ng)//2
    cnt=0
    for j in range(n):
        cnt+=(a[j]+chk-1)//chk-1
    if cnt > k:
        ng = chk
    else:
        ok = chk
print(ok)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=10**10
ng=1
for i in range(40):
    chk=(ok+ng)//2
    cnt=0
    for j in range(n):
        cnt+=(a[j]+chk-1)//chk-1
    if cnt > k:
        ng = chk
    else:
        ok = chk
print(ok)

Solution (Python):
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) - N <= K

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

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

max_a = max(A)
min_a = 0

while abs(max_a - min_a) > 1:
    cnt = 0
    target_length = (max_a + min_a)//2
    for a in A:
        cut_num = (a + target_length - 1)//target_length
        cnt += cut_num - 1
    if cnt > k:
        min_a = target_length
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length

print(max_a)

Solution (Python):
import sys
import numpy as np
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))
n,k = Mi()
a = np.array(sys.stdin.readline().split(), np.int64)
mina = np.sum(a//(n+k))
maxa = np.max(a)
while maxa > mina+1:
  mid = (mina+maxa)//2
  div = np.sum(np.ceil(a/mid-1))
  if div > k:
    mina = mid
  else:
    maxa = mid
  
print(maxa)

Solution (Python):
import sys
import numpy as np
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))
n,k = Mi()
a = np.array(sys.stdin.readline().split(), np.int64)
sa = np.sum(a)
mina = sa//(n+k)
maxa = np.max(a)
while maxa > mina+1:
  mid = (mina+maxa)//2
  div = np.sum(np.ceil(a/mid-1))
  
  if div > k:
    mina = mid
  else:
    maxa = mid
  
print(maxa)

Solution (Python):
def check(numbers, threshold):
    
    total = 0
    
    for number in numbers:
        d, m = divmod(number, threshold)
        if m == 0:
            d -= 1
        total += d
    return total
    
def main():
    n, k = map(int, input().rstrip().split(" "))
    
    numbers = list(map(int, input().rstrip().split(" ")))
    
    bottom, top = 1, 2 * (10 ** 9)
    
    while bottom < top:
        
        if check(numbers, (bottom + top )// 2) <= k:
            top = (bottom + top )// 2
        else:
            bottom = ((bottom + top )// 2) + 1
    print(top)
    
if __name__ == '__main__':
    main()

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def cut(a, l):
    res = 0
    for ai in a:
        res += max(0, (ai-1)//l)
        
    return res


def main():
    n, k = na()
    a = na()
    ansl, ansr = 0, 10**9
    while ansl + 1 < ansr:
        now = (ansl + ansr) // 2
        
        if cut(a, now) <= k:
            ansr = now
        else:
            ansl = now
    print(ansr)

if __name__ == "__main__":
    main()

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

l=0
r=10**9

while r-l>1:
    mid=(r+l)//2
    cnt=0
    for i in range(n):
        cnt+=(a[i]-1)//mid
    if cnt>k:
        l=mid
    else:
        r=mid
print(r)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)
import math






INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:
            r = test
        if int(r) == r and r-l < 1:
            print(int(r))
            return

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)
import math






INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:
            r = test
        if int(r) == r and r-l < 1:
            print(int(r))
            return

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Solution (Python):

import math
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, K, AS):
    left = 0
    right = max(AS) + 1

    while left < right - 1:
        mid = (left + right) // 2
        s = sum(a // mid - 1 if a >= mid else 0 for a in AS)
        debug(": ", mid, s)
        if s >= K:
            left = mid
        else:
            right = mid

    x = left
    debug("x: x", x)
    
    
    queue = []

    leftK = 0
    for i in range(N):
        a = AS[i]
        numDivide = a // x
        leftK += numDivide
        length = a / (numDivide + 1) if numDivide else a
        queue.append((length, numDivide, a))
    debug(": leftK", leftK)
    queue.sort()
    from heapq import heappush, heappop
    for i in range(leftK - K):
        
        (length, numDivide, a) = heappop(queue)
        numDivide -= 1
        debug(": a, numD", a, numDivide)
        length = a / (numDivide + 1) if numDivide else a
        if numDivide:
            heappush(queue, (length, numDivide, a))
        debug(": length", length)

    return math.ceil(length)
    


def solve(N, K, AS):
    left = 0
    right = max(AS) + 1

    while left < right - 1:
        mid = (left + right) // 2
        s = sum((a + mid - 1) // mid - 1 if a >= mid else 0 for a in AS)
        debug(": ", mid, s)
        if s > K:
            left = mid
        else:
            right = mid
    return right


def main():
    
    N, K = map(int, input().split())
    AS = list(map(int, input().split()))
    print(solve(N, K, AS))



T1 = """
2 3
7 9
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
4
"""

T2 = """
3 0
3 4 5
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
5
"""

T3 = """
10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
292638192
"""

T4 = """
2 1
4 2
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
2
"""

T5 = """
2 1
5 2
"""
TEST_T5 = """
>>> as_input(T5)
>>> main()
3
"""

T6 = """
2 1
3 2
"""
TEST_T6 = """
>>> as_input(T6)
>>> main()
2
"""

T7 = """
2 2
3 2
"""
TEST_T7 = """
>>> as_input(T7)
>>> main()
2
"""

T8 = """
2 2
3 1
"""
TEST_T8 = """
>>> as_input(T8)
>>> main()
1
"""

T9 = """
3 1
3 4 5
"""
TEST_T9 = """
>>> as_input(T9)
>>> main()
4
"""

T10 = """
3 2
3 4 5
"""
TEST_T10 = """
>>> as_input(T10)
>>> main()
result
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Solution (Python):
N,K = map(int,input().split())

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

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

ng,ok = 0, 10**9+1

while ok-ng > 1:
  x = (ok+ng)//2

  if check(x):
    ok = x
  else:
    ng = x

print(ok)

Solution (Python):
import math
n,k=map(int,input().split())
log=list(map(int,input().split()))
a=0
b=max(log)
if b==1:
  print(1)
  exit()
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(log[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)

Solution (Python):


n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
if k == 0:
    print(a_list[0])
else:
    start = 1
    end = a_list[0]
    x = (start + end) // 2 
    while True:
        k_count = 0
        flag = 1
        for a in a_list:
            temp_k = 0
            if a % x == 0:
                temp_k = a // x - 1
            else:
                temp_k = a // x
            if temp_k == 0:
                flag = 1
                break
            k_count += temp_k
            if k_count > k:
                flag = 0
                break
        if flag == 1:
            end = x
        if flag == 0:
            start = x
        next_x = (start + end) // 2
        if next_x == x:
            if flag == 1:
                print(x)
            if flag == 0:
                print(x + 1)
            break
        x = next_x