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 = [*map(int, input().split())]
ng, ok = 0, max(A) # (ng,ok] = (l,r]
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a-1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 10**9 # (ng,ok] = (l,r]
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a - 1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
ok = 10**9
ng = 0
while abs(ng-ok) > 1:
    mid = (ok + ng) // 2
    cnt = 0
    for i in a:
        cnt += (i+mid-1)//mid-1
    if cnt <= k:
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Accepted

Solution code:
import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += (math.ceil(A[i] / mid) - 1)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

if K == 0:  print(max(A))
else:
    left = max(A)
    right = 0
    ret = binary_search(right, left)
    print(ret)

Submission status: Accepted

Solution code:
import numpy as np
def solve(n, k, a):
    lb = 0
    ub = np.max(a)
    while ub - lb > 1:
        cur = (lb + ub) // 2
        cnt = np.sum(np.ceil(a/cur)) - n
        if cnt > k:
            lb = cur
        else:
            ub = cur
    return int(np.ceil((lb+ub) / 2))

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

Submission status: Accepted

Solution code:
import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
a=max(A)
l=1
y=copy.copy(a)
a=a-1
while l<=a:
    x=(l+a)//2
    m=0
    for i in range(N):
        if A[i]%x==0:
            m+=A[i]//x-1
        else:
            m+=A[i]//x
    if m<=K:
        a=x-1
        y=copy.copy(x)
    else:
        l=x+1
print(y)

Submission status: Accepted

Solution code:
N, K = map(int, input().split()[:2])
arr = list(map(int, input().split()[:N]))


def pos(X):
    sum = 0
    for i in arr:
        sum += int(i/X)
        if i % X == 0:
            sum -= 1
    return sum <= K


low = 1
high = 10 ** 9
mid = 0
ans = 10**9

while low <= high:
    mid = int((low+high)/2)
    # print(low, mid, high)
    if pos(mid):
        ans = mid
        high = mid-1
    else:
        low = mid+1
    # print(pos(mid))
print(ans)

Submission status: Accepted

Solution code:
from math import ceil

N,K,*A = map(int, open(0).read().split())
left = 1
right = max(A)
while left != right:
    mid = (left+right) // 2
    temp = 0
    for x in A:
        temp += ceil(x/mid) - 1
        if temp > K:
            left = mid + 1
            break
    else:
        right = mid
for i in range(max(1,left-1),left+2):
    temp = 0
    for x in A:
        temp += ceil(x/i) - 1
        if temp > K:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
import math
def check(a,mid,k):
	cnt = 0
	for x in a:
		cur_cnt = (x+mid-1)//mid - 1
		cnt+=cur_cnt
		if cnt > k:
			return False
	return True

def solve():
	n , k= map(int, input().strip().split())
	a= [int(x) for x in input().strip().split()]
	l = 0
	r = 10**9+20
	while r-l > 1:
		mid = (r+l)//2
		if check(a,mid,k):
			r = mid
		else:
			l = mid
	return l+1
 
print(solve())

Submission status: Accepted

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

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

minlen = 0
maxlen = 10**9

while maxlen-minlen > 1:
  mid = (maxlen + minlen)//2
  if mid == 0:
    cur = 1e9
  else:
  	cur = sum((a+mid-1)//mid - 1 for a in A)
  
  if cur > K:
    minlen = mid
  else:
    maxlen = mid

print(maxlen)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:l,r,*_=(l,x:=l+r>>1,r)[-sum(-b//x+1for b in a)>k:]
print(r)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:x=l+r>>1;l,r,*_=(l,x,r)[-sum(-b//x+1for b in a)>k:]
print(r)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(l:=0).read().split())
r=10**9
while~l+r:x=l+r>>1;l,r,*_=(l,x,r)[-sum(-b//x+1for b in a)>k::]
print(r)

Submission status: Accepted

Solution code:
#abc174_e

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
    
ok=1001001001
ng=0
def check(x):
  cnt=0
  for q in a:
    cnt+=(q-1)//x
  return cnt<=k

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

Submission status: Accepted

Solution code:
#abc174_e

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
    
ok=1001001001
ng=0
def check(x):
  cnt=0
  for q in a:
    cnt+=(q-1)//x
  return cnt<=k

while ok-ng>1:
  mid=(ok+ng)//2
  if check(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()))
A.sort()
right = A[-1]+1
left = 0
flag = True
mid = (left+right)//2
minN = right
result = mid
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
        if minN>mid:
            minN = mid
            result = mid
    elif count > K:
        left = mid
print(result)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = a[-1] + 1

while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    for i in a:
        cnt += (i - 1) // mid
    if cnt <= K:
        r = mid
    else:
        l = mid
print(r)

Submission status: Accepted

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

Solution code:
#abc174_e
from math import ceil
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

if k==0:
    ans=max(a)
    print(ans)
    exit()
if k==1:
    if n==1:
        print(-(-a[0]//2))
        exit()
    ans=max(a[-1]/2,a[-2])
    print(ceil(ans))
    exit()
    
ok=10**9+1
ng=1
def check(x):
    k_cnt=0
    for q in a:
        k_cnt+=ceil(q/x-1)
    if k_cnt<=k:
        return True
    else:
        return False

    
for i in range(100):
    mid=(ok+ng)/2
    if check(mid):
        ok=mid
    else:
        ng=mid
    # print(ok,ng)
print(ceil(ok))

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)


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

def check(x):
    sum_cut = 0
    for i in range(N):
        sum_cut += math.ceil(a[i]/x) - 1
    if sum_cut <= K:
        return True
    else:
        return False

M = 10**9 + 1
m = 1

x = (m+M) // 2

while True:
    y = x
    if check(x):
        M = x
        x = (m + x) // 2
    else:
        m = x
        x = (x + M) // 2

    if x == y:
        if check(x):
            print(x)
            sys.exit()
        else:
            print(x+1)
            sys.exit()

Submission status: Accepted

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

def f(x):
    count = 0
    for ai in a:
        count += (ai // x) - (ai % x == 0)
    return count <= k

left, right = 0, 10 ** 9
while right - left > 1:
    x = (left + right) // 2
    if f(x):
        right = x
    else:
        left = x

print(right)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
arr = list(map(int, input().split()))
def f(x):
    res = 0
    for i in range(N):
        if arr[i] % x != 0:
            res += arr[i]//x
        else:
            res += max((arr[i]//x)-1,0)
    return res
left = 0
right = max(arr)
while abs(left-right) > 1:
    tmp = (left+right)//2
    if f(tmp) > K:
        left = tmp
    else:
        right = tmp
print(right)

Submission status: Accepted

Solution code:
from heapq import heapify


def resolve():
    '''
    code here
    '''
    import math
    N, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

    def f(x):
        res = 0
        for item in As:
            res += (item-1)//x

        return res

    ng = 0
    ok = max(As)

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

        if f(mid) > K:
            ng = mid
        else:
            ok = mid
            
    print(ok)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
def ok(l):
    cnt = 0
    for L in a:
        cnt += L//l
        if L%l != 0:
            cnt +=1
        cnt-=1
    return cnt<=k

bot,top=0,max(a)
while top - bot >1:
    mid = (top + bot) //2
    if ok(mid): top = mid
    else: bot = mid
print(top)

Submission status: Accepted

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

def valid(arr,l,cuts):
	#cuts = k
	#print(arr,l,cuts)
	for i in arr:
		cuts-=math.ceil((i)/l)-1;
	#print(cuts)
	return cuts>=0;

n , k = map(int , input().split())
arr = list(map(int , input().split()))
arr.sort()
lo = 1
hi = max(arr)
while lo != hi:
	mid = (hi + lo)//2
	#print(mid,hi,lo)
	if valid(arr , mid,k):
		#print("he")
		#break
		hi = mid
	else:
		lo = mid + 1
print(lo)

Submission status: Accepted

Solution code:
# にぶたん　二分探索
n, k = map(int, input().split())
A = list(map(int, input().split()))

ng = 0
ok = max(A)

while abs(ok - ng) > 1:
  mid = (ok + ng) // 2
  cnt = 0
  for a in A:
    cnt += (a - 1) // mid
  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()))


def judge(length):
    cnt = 0
    for a in A:
        cnt += a // length
        if a % length == 0:  # ちょうど割り切れるときは切る回数が一回少なくて済む
            cnt -= 1
    return cnt <= k


ng, ok = 0, max(A)
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if judge(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Accepted

Solution code:
from math import ceil
N,K = map(int,input().split())
A = list(map(int,input().split()))
lb = 0
ub = max(A)
while True:
    X = (ub+lb)/2
    count = 0
    for i in range(N):
        count += ceil(A[i]/X-1)
    if count > K:
        lb = X
    else:
        ub = X
    if ceil(ub) == ceil(lb):
        print(ceil(ub))
        exit()

Submission status: Accepted

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

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

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

print(ok)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    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
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

Submission status: Accepted

Solution code:
from math import ceil

def check(A, K, L):
    i = 0
    for a in A:
        i += ceil(a/L)-1
        if i > K:
            return False
    return True

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
l = 0
r = A[0]
while l + 1 < r:
    m = (l+r)//2
    if check(A, K, m):
        r = m
    else:
        l = m
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_ok(mid):
    cnt = 0
    for i in range(n):
        cnt += (a[i] - 1) // mid
    return cnt <= k

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

ok = 10 ** 18
ng = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Submission status: Accepted

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

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

#答えの範囲
left = 0
right = 10**9

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

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    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+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)

Submission status: Accepted

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

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

#めぐる式そのまま
ok = 10**9
ng = 0
while ok-ng > 1:
  mid = (ok + ng)//2
  if check(mid):
    ok = mid
  else:
    ng = mid

print(ok)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N,K = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    left = 0
    right = A[-1]

    while right - left > 1:
        cnt = 0
        middle = (left + right) // 2
        for i in A:
            cnt += (i - 1) // middle
        if cnt <= K:
            right = middle
        else:
            left = middle
    print(right)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

N,K = map(int,input().split())
A = list(map(int,input().split()))
if K == 0:
    print(max(A))
else:
    s = 0
    g = 10**9
    mae = -1
    now = 1
    while now != mae:
        mae = now
        c = 0
        if (s + g)%2 == 0:
            now = (s + g)//2
        else:
            now = (s + g)//2+1        
        for i in range(N):
            if A[i]%now == 0:
                c += (A[i]//now)-1
            else:
                c += A[i]//now
        if c > K:
            s = now
        else:
            g = now
        #print(now,c)
    print(now)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
l = list(map(int,input().split()))
def cnt_check(longest):
    if longest == 0:
        return False
    cnt = 0
    for log in l:
        cnt += math.ceil(log/longest)-1
    if cnt <= k:
        return True
    else:
        return False
left = 0
right = max(l)
while right - left > 1:
    middle = (left + right)//2
    if cnt_check(middle):
        right = middle
    else:
        left = middle
print(right)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=0
r=a[-1]
while r-l>1:
  cnt=0
  m=(l+r)//2
  #print("l,m,r",l,m,r)
  for i in a:
    cnt+=(i-1)//m
  if cnt<=k:
    r=m
  else:
    l=m
print(r)

Submission status: Accepted

Solution code:
def examA():
    X = I()
    if X<30:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)
    return

def examB():
    N, D = LI()
    cnt = 0
    for _ in range(N):
        x, y = LI()
        if x**2+y**2<=D**2:
            cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    N = 10**7
    K = I()
    cur = 0
    now = 1
    ans = -1
    for i in range(N):
        cur += 7 * now
        cur %= K
        if cur==0:
            ans = i+1
            break
        now *= 10
        now %= K
    print(ans)
    return

def examD():
    N = I()
    C = SI()
    cnt = 0
    l = 0; r = N-1
    while(l<r):
        while(l<N):
            if C[l]=="W":
                break
            l += 1
        while(0<=r):
            if C[r]=="R":
                break
            r -= 1
        if l<r:
            cnt += 1
            l += 1
            r -= 1
    ans = cnt
    print(ans)
    return

def examE():
    N, K = LI()
    A = LI()
    if K==0:
        print(max(A))
        return
    l = 0; r = inf
    while(r-l>1):
        now = (l+r)//2
        cnt = 0
        for a in A:
            cur = a//now
            if a%now==0:
                cur -= 1
            cnt += cur
        if cnt<=K:
            r = now
        else:
            l = now
        #print(now,cnt)
        #input()
    ans = r

    print(ans)
    return

def examF():
    # 0は絶対に入れない!!
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            # i==0 はだめ => 全部+1するとか
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
            # maspyさんの参考　よくわかってない
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i + 1

        def debug(self, k):
            return [self.sum(i) for i in range(k)]

        def inversion(self, A=[3, 10, 1, 8, 5]):
            res = 0
            for i, p in enumerate(A):
                self.add(p, 1)
                res += i + 1 - self.sum(p)
            return res
    N, Q = LI()
    C = LI()
    LR = []
    lastAppeared = [-1]*N
    for i in range(Q):
        l, r = LI()
        LR.append((l,r,i))
    LR.sort(key=lambda x:x[1])
    #print(LR)
    bit = Bit(N+1)
    ans = [0]*Q
    r = 0
    now = 0
    while(r<N):
        if now==Q:
            break
        l0, r0, i0 = LR[now]
        while(r<r0):
            c = C[r]-1
            if lastAppeared[c]>0:
                bit.add(lastAppeared[c],-1)
            lastAppeared[c] = r+1
            bit.add(lastAppeared[c]+1)
            r += 1
        #print(bit.debug(r))

        while(now<Q):
            l0,r0,i0 = LR[now]
            if r<r0:
                break
            #print(r,now)
            ans[i0] = bit.sum(r0)
            if l0>1:
                ans[i0] -= bit.sum(l0-1)
            now += 1


    for v in ans:
        print(v)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<60
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 9

sys.setrecursionlimit(10**5)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    n, k = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    
    def ok(ans):
        cnt = sum(max((i - 1) // ans, 0) for i in a)
        # print(ans, cnt) 
        return cnt <= k
    
    ans = 0
    for i in range(32, -1, -1):
        if not ok(ans + (1 << i)):
            ans += 1 << i
    print(ans + 1)

main()

Submission status: Accepted

Solution code:
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))

Submission status: Accepted

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


# k回以下の試行でにすべての長さをl以下にできるか
def isDividable(l,k,a):
  cnt = 0
  for Log in a:
    cnt += (Log - 1) // l
  return cnt <= k


#bottom = ng,top = ok
def binary_search(ng,ok,k,a):
  while abs(ng-ok) > 1:
    mid = (ng + ok) // 2
    if isDividable(mid,k,a):
      ok = mid
    else:
      ng = mid
  return ok


# @njit
def solve(k,a):
  return binary_search(0,max(a),k,a)



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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())

n,k=ma()
a=lis()
l,h=0,max(a)
while(l+1<h):
    m=(l+h)//2
    c=0
    for i in a:
        c+=ceil(i/m)-1
    if(c<=k):
        h=m
    else:
        l=m
print(h)

Submission status: Accepted

Solution code:
import math

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

left=0
right=max(a)
mid = (left+right)/2
while right - left > 0.5:
    times = 0
    for i in range(n):
        times+=math.ceil(a[i]/mid)-1
    if times<=k:
        right=mid
        mid=(left+right)/2
    else:
        left = mid
        mid =(left+right)/2

print(math.ceil(mid))

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
cs = list(map(int, input().split()))
high = max(cs) + 1  # OK が取れる側
low = 0  # NG となる側
 
while high - low > 1:
  x = (high - low) // 2 + low
  cnt = 0
  for a in cs:
    cnt += math.ceil(a/x) - 1
 
  if cnt <= K:  # OK
    high = x
  else:
    low = x
print(high)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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  # OK が取れる側
    low = 0  # NG となる側

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

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

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

    print(high)


main()

Submission status: Accepted

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

        if middle == 0:
            break

        # 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 test_1original_1(self):
        test_input = """2 4
2 3"""
        output = """1"""
        self.assertIO(test_input, output)


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

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

Submission status: Accepted

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

#x回切ると1/(x+1)倍になる


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
# Max x for check(x) == True
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)

Submission status: Accepted

Solution code:
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
#        print(ok, ng)
    return ok

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

Submission status: Accepted

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