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()))

max_a = 10**9
min_a = 0
while True:
    k = K
    res = (max_a+min_a)//2
    for i in range(N):
        if a[i] <= res:
            continue
        k -= (a[i]//res)
    if k >= 0:
        max_a = res
    else:
        min_a = res
    if max_a - min_a == 1:
        break
print(max_a)

Submission status: Accepted

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

"""
目標とする最長の長さをxとして、それをk回で達成
できるか
aをソートしたので、途中でkを超えることが判明したら打ち切る
"""

def isOK(x):
    cnt = 0
    for _a in a:
        if _a<=x:
            return True
        try:
            cnt+=_a//x
        except:
            return False
        if cnt>k:
            return False
    return True

ng = 0
ok = 10**9+1

while abs(ng-ok)>0.1:
    mid = (ng+ok)/2
    if isOK(mid):
        ok = mid
    else:
        ng = mid
    if ok < 1:
        break
ok = ceil(ok)
if isOK(ok-1):
    print(ok-1)
else:
    print(ok)

Submission status: Accepted

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

X = list(range(1,N+1))
lo = 1
hi = max(A)

while hi-lo>=2:
    mid = (lo+hi)//2
    
    temp = list(map(lambda x:  x//mid - (x%mid==0) ,A))
    if sum(temp) <= K:
        hi = mid
    else:
        lo = mid

temp = list(map(lambda x:  x//lo - (x%lo==0) ,A))

if sum(temp) <= K:
    print(lo)
else:
    print(hi)

Submission status: Accepted

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


def isOk(m):
    k = 0
    for a in A:
        if a > m:
            k += a//m
            if a % m == 0:
                k -= 1
    if k <= K:
        return True
    else:
        return False


l, r = 10**19, 1
while abs(r-l) > 1:
    m = (l+r)//2
    if isOk(m):
        l = m
    else:
        r = m

if isOk(r):
    print(r)
else:
    print(l)

Submission status: Accepted

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

l = 1
h = a[0]
while l != h:
    m = (l + h) // 2
    cut = 0
    for x in a:
        cut += x // m + (x % m != 0) - 1
    if cut <= k:
        h = m
    else:
        l = m + 1

print(l)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
maxa = max(As)

l, r = 0, maxa+1
while r-l>1:
    half = (l+r)//2
    cnt = 0
    for a in As:
        cnt += -(-a//half)-1
    if cnt>K:
        l = half
    else:
        r = half

print(r)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

ok=max(a)
ng=0

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

  num=0
  for i in a:
    if i%m!=0:
      num+=(i//m)
    else:
      num+=(i//m)-1

  if num<=k:
    ok=m
  else:
    ng=m

print(ok)

Submission status: Accepted

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


x0, x1 = 0, 10**9
while x0+1 < x1:
    x = (x0+x1)//2
    s = sum((a-1)//x for a in A)
    
    if s > K:
        x0 = x
    else:
        x1 = x

print(x1)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
start = 1
end = max(a)
bs = 1
be = max(a)
while start != end:
    center = (start+end)//2
    tnp = 0
    for i in range(n):
        tnp += (a[i]-1)//center
    #print(start,end,center,tnp)
    if (tnp>k):
        start = center
    else:
        end = center
    if (start==bs and end==be):
        x = 0
        for j in range(n):
            x += (a[j]-1)//start
        y = 0
        for j in range(n):
            y += (a[j]-1)//end
        #print(x,y)
        #print(x,y)
        if (x<=k):
            print(start)
        else:
            print(end)
        exit()
    bs = start
    be = end
    
print(start)

Submission status: Accepted

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

"""
切る回数は広義単調減少になる
にぶたん
"""

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

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

print(ok)

Submission status: Accepted

Solution code:
def binary_search(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        cnt = 0
        for i in a:
            cnt += (i - 1) // m
        #print(cnt, m)
        if cnt <= k:
            c2 = m
        else:
            c1 = m
        return binary_search(c1, c2)

n, k = map(int, input().split())
a = list(map(int, input().split()))
x = binary_search(0, 10 ** 9)
for i in range(x + 5, max(x - 5, 0), -1):
    cnt = 0
    for j in a:
        cnt += (j - 1) // i
    if cnt <= k:
        ans = i
print(ans if not k == 0 else max(a))

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush
from math import ceil
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
total = sum(A)
H = []
remnant = K
for a in A:
    n = (K*a)//total
    remnant -= n
    H.append((-a/(n+1), n, a))
heapify(H)
for k in range(remnant):
    L, n, a = heappop(H)
    heappush(H, (-a/(n+2), n+1, a))
ans = int(ceil(-H[0][0]))
print(ans)

Submission status: Accepted

Solution code:
import sys

# 丸太をk回以下切ってすべてx以下にできる
def c(a, k, x):
    cnt = 0
    for log in a:
        if log < x:
            continue
        if log % x == 0:
            cnt += log // x - 1
        else:
            cnt += log // x
        if cnt > k:
            return False
    return True


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    lb = 0
    ub = 11 ** 9
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if c(a, k, mid):
            ub = mid
        else:
            lb = mid
    print(ub)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

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

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



print(binary_search_int(10**9+100,0,test))

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = k
    for i in a:
        tmp = math.ceil(i / x)
        cnt -= tmp - 1
        if cnt < 0:
            return False
    return True

n, k = LI()
a = LI()
a.sort(reverse=True)
ok = sum(a)
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if f(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()))

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

max_ng = 0
min_ok = 10**9
while min_ok-max_ng>1:
    tgt = (min_ok+max_ng)//2
    if check(tgt):
        min_ok = tgt
    else:
        max_ng = tgt

print(min_ok)

Submission status: Accepted

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

ll=0
rr=10**9+1
for _ in range(10**2):
  #最も長い丸太がこれになる
  ans=(ll+rr)/2.0
  cnt=0
  for item in a:
    if item>ans:
	    cnt+=((-1*item)//ans)*(-1)-1
  if cnt<=k:
    rr=ans
  else:
    ll=ans
print(int((-1*ans//1)*(-1)))

Submission status: Accepted

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

def is_ok(l):
    if l<=0: return False
    k = 0
    for a in A:
        k += a//l
        if a%l==0:
            k -= 1
        if k > K:
            return False
    return True

ok = 10**9+1
ng = -1
while ok - ng > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Submission status: Accepted

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

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

l=1
r=10**9
import math
for i in range(100):
    temp=0
    m=(r+l)/2
    for j in a:
        temp+=j//m
    if temp<=k:
        r=m
    else:
        l=m

print(math.ceil(m))

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:

    m = (l+r)//2

    now = 0
    for i in range(N):
        if A[i] % m == 0:
            now += A[i] // m -1
        else:
            now += A[i] // m

    if now > K:
        l = m
    else:
        r = m

print (r)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(10**7)

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

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n,k,*A = get_all_int()

    # NGの上限
    l = 0
    # OKの下限
    r = 10**9

    while l+1 < r:
        c = (l+r)//2

        # 全ての丸太を長さc以下にするのに何回かかるか？
        x = 0
        for a in A:
            # 切り上げ-1
            x += (a+c-1)//c - 1
        
        # log(l, r, c, x)

        if x <= k:
            # OK
            r = c
        else:
            # NG
            l = c

    print(r)

main()

Submission status: Accepted

Solution code:

def solve():
  N, K = [int(x) for x in input().split()]
  A = [int(x) for x in input().split()]
  s, l = 0, 10**9
  # s: largest proven impossible
  # l: smallest proven possible
  while s + 1 < l:
    x = (s + l) // 2
    #print(x, s, l)
    c = 0
    for a in A:
      c += -(-a//x) - 1
    #print(c)
    if c <= K:  # x was possible
      l = x
    else:
      s = x
  return l
print(solve())

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[int(j) for j in input().split()]
a.sort(reverse=True)
def f(x):
    c=0
    for i in a:
        if i<x:
            break
        c+=-(-i//x)-1
        if c>k:
            return False
    return True
left=0
right=a[0]
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid
    else:
        left=mid
print(right)

Submission status: Accepted

Solution code:

import numpy as np
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
np_A=np.array(A)

def ch(np_A,ans):
    tmp=(np_A-1)//ans
    if np.sum(tmp)<=k:
        return True
    else:
        return False


low=1
high=max(A)
while low<high :
    mid=(high+low)//2
    if ch(np_A,mid):
        high=mid
    else:
        low=mid+1
print(high)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
l = 0 
h = a[0]
def pos(b):
  c = 0
  for i in range(n):
    if a[i] <= b:
      break
    c += math.ceil(a[i]/b)-1
    if c > k:
      return False
  return True
while l+1 < h:
  m = (l+h)//2
  if pos(m):
    h = m
  else:
    l = m
print(h)

Submission status: Accepted

Solution code:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy
import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

def to10(A):
    ret=0
    for a in range(len(A)-1,-1,-1):
        ret+=X[a]*2**(N-1-a)
    return ret
######################################################################################################
def f(m,K,A):
    cnt=0
    for a in A:
        cnt+=(a+m-1)//m-1
    return cnt<=K
N,K=inputintlist()
A=inputintlist()
l=0
r=max(A)
for a in range(60):
    m=(l+r)//2
    if m==0:
        break
    if f(m,K,A):
        r=m
    else:
        l=m
print(r)

Submission status: Accepted

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

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int((a-0.01)/x)
        if cnt > k:
            return False
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-2
r = 10**9
while r-l > 10**-1:
    m = (l*r)**0.5
    if f(m):
        r = m
    else:
        l = m
print(int(l)+1)

Submission status: Accepted

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

def possible(l):
    if l==0:
        return False
    c = 0
    for i in range(N):
        if A[i]%l==0:
            n = A[i]//l-1
        else:
            n = A[i]//l
        c += n
    return c<=K

l = 0
r = max(A)
m = (l+r)/2
for i in range(32):
    pos = possible(m)
    if pos:
        r = m
    else:
        l = m
    m = (l+r)/2

if possible(int(m)):
    print(int(m))
else:
    print(ceil(m))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
  chk=0
  for ai in a:
    # 長さx以下に分割するなら最小でtmp本にわかれる
    tmp=math.ceil(ai/x)
    chk+=tmp
  return chk<=n+k
l,r=0,max(a)
for _ in range(50):
  x=(l+r)/2
  if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
    l,r=l,x
  else:
    l,r=x,r
x=(l+r)/2
print(math.ceil(x))
#print(l,r,x)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[int(j) for j in input().split()]
a.sort(reverse=True)

def f(x):
    c=0
    for i in a:
        if i<x:
            break
        c+=-(-i//x)-1
        if c>k:
            return False
    return True



left=0
right=a[0]
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid
    else:
        left=mid
print(right)

Submission status: Accepted

Solution code:
ans,A,N,K = 0,0,0,0

def a():
    global ans,A,N,K
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    if K == 0:
        return max(A)

    def dividable(x):
        global ans,A,N,K
        ans = 0
        for a in A:
            if a % x == 0:
                ans += a // x - 1
            else:
                ans += a // x
        return ans <= K

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

print(a())

Submission status: Accepted

Solution code:
import sys
import math
def main():
  n, k = map(int, input().split())
  a = list(map(int, input().split()))
  lo = 1
  up = 10**9 + 1
  while up-lo != 1:
    mid = (up + lo)//2
    temp =  0
    for i in a:
      temp += math.ceil(i / mid)-1
    if temp <= k:
      up = mid
    else:
      lo = mid
  temp = 0
  for i in a:
    temp += math.ceil(i/lo)-1
  if  temp <= k:
    print(lo)
  else:
    print(up)
      

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import math

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

left = 0
right = max(a)

while True:
  mid = (left + right) // 2
  
  if mid == 0:
    cnt = 10 ** 10
  else:
    cnt = 0
    for _a in a:
      cnt += math.ceil(_a / mid - 1)
  
  if cnt > k:
    left = mid
  else:
    right = mid
  
  if right - left <= 1:
    break

print(right)

Submission status: Accepted

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


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

    l = 0
    r = max(A)

    while l+1 < r:
        count = 0
        length = (l+r) // 2
        for a in A:
            count += (a-1) // length

        if count <= k:
            r = length
        else:
            l = length

    print(r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ceil = lambda a, b: (a + b - 1) // b

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

# bisect
l, r = 0, max(A)
while r - l > 1:
    m = (l + r) // 2
    if sum(ceil(x, m) - 1 for x in A) > K:
        l = m
    else:
        r = m
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()))

x = max(A)

mn = 0
mx = max(A)

while mx-mn > 1:
    suc = True
    cnt = 0
    for a in A:
        cnt += -((-a)//x) - 1
        if cnt > K:
            suc = False
            break
    if suc:
        mx = x
        x = (mn+mx)//2
    else:
        mn = x
        x = (mn+mx)//2

print(mx)

Submission status: Accepted

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


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


L = 0
R = 10**10
while L != R-1:
    M = (L+R)//2
    if check(M):
        L = M
    else:
        R = M
print(R)

Submission status: Accepted

Solution code:
class RemovableHeap:
    def __init__(self, is_max_heap: bool=False, data :list=None):
        self.data = [] if data is None else data
        self.erased = []
        self.sign = -1 if is_max_heap else 1
    
    def normalize(self):
        while len(self.erased) > 0 and self.data[0] == self.erased[0]:
            heappop(self.data)
            heappop(self.erased)
    
    def pop(self):
        ret = self.sign * heappop(self.data)
        self.normalize()
        return ret

    def push(self, x):
        heappush(self.data, self.sign * x)
        self.normalize()
    
    def remove(self, x):
        heappush(self.erased, self.sign * x)
        self.normalize()
    
    def __len__(self):
        return max(len(self.data) - len(self.erased), 0)
    
    def get(self):
        return self.sign * self.data[0]


def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    from heapq import heapify, heappop, heappush
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N,K = LMIIS()
    A = LMIIS()
    def f(x):
        if x == 0:
            return False
        count = 0
        for a in A:
            count += ceil(a/x) -1
        return count <= K
    
    ng = 0
    ok = 10**9+1
    while ok - ng > 1:
        dbg(ng,ok)
        m = (ng+ok)//2
        if f(m):
            ok = m
        else:
            ng = m
    print(ok)

    
main()

Submission status: Accepted

Solution code:

import math

def cut(l, e):
    """全ての木片が長さl以下になるように切った時、
    eを処理するのに何回かかるか
    """
    return math.ceil(e / l) - 1


def judge(a, k, l):
    cuts = 0
    for e in a:
        cuts += cut(l, e)
    return cuts <= k


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

    l = 0
    r = max(a)
    while abs(r - l) > 0.000001:
        m = (l + r) / 2
        if judge(a, k, m):
            r = m
        else:
            l = m

    print(math.ceil(m))


submit()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, K = in_nn()
    A = in_nl()

    def judge(x):

        cnt = 0
        for i in range(N):
            q, r = divmod(A[i], x)
            if r == 0:
                q -= 1
            cnt += q

        return cnt <= K

    def binary_search(min_n, max_n):

        while max_n - min_n != 1:
            mid = (min_n + max_n) // 2
            if judge(mid):
                max_n = mid
            else:
                min_n = mid

        return max_n

    ans = binary_search(min_n=0, max_n=10**9)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, math, bisect

def search_bisect(N, K, A_list):
    times = 32
    left = 0
    right = A_list[-1]


    while( math.ceil(left) != math.ceil(right) ):
        """
        全ての板を長さmid以下にできるかを二分探索で探す
        True -> より小さい長さにチャレンジ
        False -> より長いものでチャレンジ

        M回の切断で長さSの板は、長さS/(M+1)の板(M+1)本に切断可能
        """
        mid = (left+right)/2
        index = bisect.bisect_right(A_list, mid)
        time = 0

        for i in range(index, N):
            time +=math.ceil(A_list[i]/mid)-1
        if(time <= K):
            #success
            right = mid
        else:
            left = mid
    return math.ceil(left)



if(__name__ == "__main__"):
    """
    N, D = map(int, input().strip().split() )
    D_sq = D**2
    xy_list = []
    for i in range(N):
        xy = list( map(int, input().strip().split() ) )
        xy_list.append(xy)
    """
    N, K = map(int, input().strip().split() )
    A_list = list( map(int, input().strip().split() ) )

    A_list.sort()
    if(K==0):
        print(A_list[-1])
    else:
        length = search_bisect(N, K, A_list)
        print(length)