Problem:


Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192



Sample input:
2 3
7 9


Sample output:
4

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(1000):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Submission status: Runtime Error

Solution code:
import math
N, K=map(int, input().split())
A=list(map(int, input().split()))
i=1
j=10**9
while True:
    k=(i+j)//2
    if sum([math.ceil(a/k)-1 for a in A])<=K:
        if k-1>0 and sum([math.ceil(a/(k-1))-1 for a in A])>K:
            print(k)
            break
        else:
            j=k-1
    else:
        i=k+1

Submission status: Runtime Error

Solution code:
import math
N, K=map(int, input().split())
A=list(map(int, input().split()))
i=1
j=10**9
while True:
    k=(i+j)//2
    if sum([math.ceil(a/k)-1 for a in A])<=K:
        if sum([math.ceil(a/(k-1))-1 for a in A])>K:
            print(k)
            break
        else:
            j=k-1
    else:
        i=k+1

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2+1
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
a=np.sort(a)
if k==0:
  print(np.max(a))
  exit()
sa=np.sum(a)
one=sa//(n+k-1)
b=a/one
b=np.round(b)
sb=np.sum(b)
ak=sb/k
c=np.round(b/ak)
sc=np.sum(c)
if sc==k:
  d=c+1
  e=a/d
  print(math.ceil(np.max(e)))
else:
  d=c+1
  e=a/d
  maxone=(math.ceil(np.max(e)))
  while maxone-one>0.000001:
    mid = (maxone+one)/2
    mk = np.sum(np.ceil(a/mid-1))
    if mk>k:
      one = mid
    else:
      maxone = mid
  print(math.ceil(one))

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
#    print(m,rf(m))
    if rf(m)>(n+k) :
        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2+1
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num)
    
    return cnt


while True:
    mid = (left + right) // 2
    tmp = count(mid)
    if tmp == K:
        break
    elif tmp > K:
        if left == mid:
            mid += 1
            break
        left = mid
    else:
        right = mid

if mid == 0:
    print(mid)
    exit()

right = mid
while True:
    tmp = count(mid)
    if tmp == K and tmp != count(mid-1):
        print(mid)
        break
    elif tmp == K:
        right = mid
    else:
        if left == mid:
            print(mid+1)
            break
        left = mid
    mid = (left + right) // 2

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num)
    
    return cnt


while True:
    mid = (left + right) // 2
    tmp = count(mid)
    if tmp == K:
        break
    elif tmp > K:
        if left == mid:
            mid += 1
            break
        left = mid
    else:
        right = mid

if mid == 0:
    print(mid)
    exit()

right = mid
while True:
    tmp = count(mid)
    if tmp == K and tmp != count(mid-1):
        print(mid)
        break
    elif tmp == K:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num)
    
    return cnt


while True:
    mid = (left + right) // 2
    tmp = count(mid)
    if tmp == K:
        break
    elif tmp > K:
        if left == mid:
            mid += 1
            break
        left = mid
    else:
        right = mid


if tmp == K and tmp != count(mid-1):
    print(mid)
    exit()

if mid == 0:
    print(mid)
    exit()

right = mid
while True:
    tmp = count(mid)
    if tmp == K and tmp != count(mid-1):
        print(mid)
        break
    if tmp == K:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] // num)
    
    return cnt


while True:
    mid = (left + right) // 2
    tmp = count(mid)
    if tmp == K:
        break
    elif tmp > K:
        if left == mid:
            mid += 1
            break
        left = mid
    else:
        right = mid


if tmp == K and tmp != count(mid-1):
    print(mid)
    exit()

if mid == 0:
    print(mid)
    exit()

right = mid
while True:
    tmp = count(mid)
    if tmp == K and tmp != count(mid-1):
        print(mid)
        break
    if tmp == K:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math

N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)

def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] // num)
    
    return cnt


while True:
    mid = (left + right) // 2
    tmp = count(mid)
    if tmp == K:
        break
    elif tmp > K:
        if left == mid:
            mid += 1
            break
        left = mid
    else:
        right = mid

#print(mid)
if mid == 0:
    print(mid)
    exit()
right = mid

while True:
    #print(left, right)
    tmp = count(mid)
    #print(tmp, count(mid-1))
    if tmp == K and tmp != count(mid-1):
        #print(tmp, count(mid-1))
        print(mid)
        break
    if tmp == K:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2

Submission status: Runtime Error

Solution code:
def ceil(X, Y):  # 天井関数 ceil(X/Y) Y>1
    return (X + Y - 1) // Y


def binary(N):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        cnt = sum(ceil(ai, (l + r) // 2) - 1 for ai in a)
        if cnt <= k:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return l


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

print(binary(max(a)))

Submission status: Runtime Error

Solution code:
def ceil(X, Y):  # 天井関数 ceil(X/Y) Y>1
    return (X + Y - 1) // Y


def binary(N):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        cnt = sum(ceil(ai, (l + r) // 2) - 1 for ai in a)
        if cnt <= k:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r


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

print(binary(max(a)))

Submission status: Runtime Error

Solution code:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]
    if(k == 0):
        print(MA)
        return
    if(n == 1):
        print(MA//k)
        return
    while(True):
        m = mi + (MA - mi)//2
        #print(mi,m,MA)
        count = 0
        for i in a:
            count += i//m
        if(MA < mi):
            print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m-1
        




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]
    if(k == 0 or n == 1):
        print(MA)
        return
    while(True):
        m = mi + (MA - mi)//2
        #print(mi,m,MA)
        count = 0
        for i in a:
            count += i//m
        if(MA < mi):
            print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m-1
        




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]
    if(k == 0):
        print(MA)
        return
    while(True):
        m = mi + (MA - mi)//2
        #print(mi,m,MA)
        count = 0
        for i in a:
            count += i//m
        if(MA < mi):
            print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m-1
        




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while maxVal - minVal >= 1:
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

if not isPossible(minVal) and int(minVal) == minVal:
    print(minVal+1)
else:
    print(math.ceil(minVal))

Submission status: Runtime Error

Solution code:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]//2
    if(k == 0):
        print(MA)
        return
    while(True):
        m = mi + (MA - mi)//2
        #print(mi,m,MA)
        count = 0
        for i in a:
            count += i//m
        if(MA < mi):
            print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m-1
        




if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

    


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def mbisect(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


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


n, k = map(int, input().split())
a = tuple(map(int, input().split()))
print(mbisect(10 ** 9 + 1, -1))

Submission status: Runtime Error

Solution code:
from math import ceil

def isOK(length):
  ans = 0
  for a in A:
    ans += ceil(a / length) - 1
  return ans <= k


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

start, end = 0, 10**9 + 1
while True:
  mid = (start + end) // 2
  prev = mid - 1
  if isOK(mid):
    if isOK(prev):
      end = mid
    else:
      print(mid)
      exit()
  else:
    start = mid

Submission status: Runtime Error

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

    


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]//2
    while(True):
        m = mi + (MA - mi)//2 if (MA - mi)%2 == 0 else mi + (MA-mi)//2 + 1
        count = 0
        for i in a:
            count += i//m
        if(MA < mi):
            print(m)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m-1




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def mbisect(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok


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


n, k = map(int, input().split())
a = tuple(map(int, input().split()))
print(mbisect(10 ** 9, -1))

Submission status: Runtime Error

Solution code:
n, k, *A = map(int, open(0).read().split())
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
X = []
for a in A:
    X.append(ceil(a / ceil(a/t)))
    X.append(ceil(a / int(a/t)))
X.sort()
print(X[k] if k < len(X) else X[-1])

Submission status: Runtime Error

Solution code:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()
    a.sort(reverse=True)
    upper = 10 ** 9 + 1
    under = 0

    while upper - under > 0.01:
        middle = (upper + under) // 2

        tk = k
        flg = True
        for ai in a:
            if ai <= middle:
                break

            ta = ai
            tk -= int((ta - middle) / middle)
            if tk < 0:
                flg = False
            break

        if flg:
            upper = middle
        else:
            under = middle

    print(math.ceil(under))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, k, *A = map(int, open(0).read().split())
t = sum(A) / (n+k)
A = [a for a in A if int(a/t) >= 1]
X = []
for a in A:
    X.append(ceil(a / ceil(a/t)))
    X.append(ceil(a / int(a/t)))
X.sort()
print(X[k])

Submission status: Runtime Error

Solution code:
#import numpy as np
#import collections
#import math

#f = open('./input_E.txt')
#
#N,K = map(int, f.readline().split())
#A = list(map(int, f.readline().split()))

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

if K == 0:
    ans = max(A)
else:
    A.sort(reverse=True)
    
    All_length = sum(A)
    KK = K+N-1
    lm = All_length/(KK+1)
    
    k_list = [int(Ai//lm) for Ai in A]
    X_list = [Ai%lm for Ai in A]
    Xmax = max(X_list)

    zero_k = 0
    for i in range(1,N+1):
        if k_list[-i] == 0:
            zero_k +=1
        else:
            break
    
    sum_k = sum(k_list)-(N-zero_k)
    res_cut = K-sum_k
    
    
    if res_cut > 0:
#        think = min(7*(N//res_cut)+1,res_cut)
        ans_kouho = []
#        for i in range(-zero_k,0):
#            ans_kouho.append(A[i])
#        ans_kouho.extend(X_list)
        for i in range(res_cut):
#        for i in range(think):
            if Xmax >= i*lm:
                for j in range(N-zero_k):
#                    ans_kouho.append((X_list[j]-i*lm)/k_list[j]+1)
                    ans_kouho.append(A[j]/(k_list[j]+i))
        
        ans_kouho.sort(reverse=True)
        ans = ans_kouho[res_cut]
        ans = int(ans+1)
    else:
        ans = int(lm+1)
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    ans = 0
    left = 0
    right = len(c) - 1
    while left < right:
        if c[left] == 'R':
            left += 1
            continue
        if c[right] == 'W':
            right -= 1
            continue
        left += 1
        right -= 1
        ans += 1

    return ans


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

#めぐる式二分探索
def is_ok(i):
    su = 0
    for a in A:
        su += math.ceil(n / i) - 1
    if su <= K:
        return True
    else:
        return False

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

Submission status: Runtime Error

Solution code:
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [a/pivot for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k
if K >= 1000000:
    for i in range(N):
    h = hiritu[i]
    k = int(ceil(K*h/hirituSum))
    kaisu.append(k)
    K -= k

leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print(ceil(l))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
lo, hi = 0, 9999999999999999
while lo < hi:
    mid = (lo + hi) // 2
    cnt = 0
    for i in range(n):
        if l[i] % mid == 0: cnt += (l[i] // mid) - 1
        else: cnt += (l[i] // mid)
    if cnt <= k: hi = mid
    else: lo = mid + 1
print(lo)

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())
A = list(map(int,input().split()))
def C(x):
    num=0
    for i in range(N):
        num+=math.ceil(A[i]/x)-1
    return num>=K
def C2(x):
    num=0
    B=[0 for i in range(N)]
    for i in range(N):
        B[i]=math.ceil(A[i]/math.ceil(A[i]/x))
    return max(B)
lb=0
ub=10**9
if K==0:
    print(max(A))
else:
  for i in range(100):
    mid=(lb+ub)//2
    if C(mid):
        lb=mid
    else:
        ub=mid
  print(C2(mid))

Submission status: Runtime Error

Solution code:
import math 
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=max((left+right)//2,1)

while(right-left>=1):
    numofcut=0
    mid=(left+right)//2
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=A[i]//mid -1
        else:
            numofcut+=A[i]//mid
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    max((left+right)//2,1)

print(mid)

Submission status: Runtime Error

Solution code:
import math
N,K=map(int,input().split())
A = list(map(int,input().split()))
epsilon=0.00000000000000001
def C(x):
    num=0
    for i in range(N):
        num+=math.ceil(A[i]/x)-1
    return num>=K
def C2(x):
    num=0
    B=[0 for i in range(N)]
    for i in range(N):
        B[i]=math.ceil(A[i]/math.ceil(A[i]/x))
    return max(B)
lb=0
ub=10**9
for i in range(100):
    mid=(lb+ub)//2
    if C(mid):
        lb=mid
    else:
        ub=mid
if K==0:
    print(max(A))
else:
    print(C2(mid))

Submission status: Runtime Error

Solution code:
#揃える長さを決め打って二分探索
import sys
import math
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst1.sort(reverse=True)
def func(mid): #ここが関数部分
    res = 0
    for i in range(n):
        if mid >= lst1[i]:
            continue
        res += math.ceil(lst1[i]/mid)-1
        if res > k:
            return False
    return True


def binary_search(): #2分探索
    ok = 10**9
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid):
            ok = mid
        else:
            ng = mid

    return ok

if k == 0:
    print(max(lst1))
else:
    print(binary_search())

Submission status: Runtime Error

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
            cnt += cur
        if K<cnt:
            l = now
        else:
            r = now
        #print(now,cnt)
        #input()
    ans = l

    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 = dec("20000000000")
_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
"""