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: Wrong Answer

Solution code:
import math

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

for i in range(1, 10**5):
    cnt = 0
    for a in A:
        cnt += math.ceil(a/i) - 1
    
    if cnt <= K:
        print(i)
        exit()

Submission status: Wrong Answer

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

max_len = max(A)
def f(x):
    ans = 0
    for a in A:
        cut_num = math.ceil(a / x) - 1
        #print(a, cut_num, a / x)
        ans += cut_num
    if ans <= k:
        return True
    else:
        return False

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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.floor(A[i] / mid)
    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) + 1
    right = 0
    ret = binary_search(right, left)
    print(ret)

Submission status: Wrong Answer

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.floor(A[i] / mid)
    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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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

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

Submission status: Wrong Answer

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 = 0
high = 10 ** 9
mid = 0
ans = 10**9

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

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush, heapify 

n, x = map(int,input().split())
a = [-1*int(i) for i in input().split()]
ans = []
heapify(ans)
for i in a:
    heappush(ans, i)
while x > 0:
    t = -1*heappop(ans)
    t1,t2 = t//2,t//2+t%2
    heappush(ans, -t1)
    heappush(ans, -t2)
    x -= 1
print(-1*heappop(ans))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	if k >= 10*7:
		return 1
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	for i in range(k):
		x,cnt,orig = heappop(a)
		x = -x
		if x <= 1:
			return 1
		heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
	return -(heappop(a)[0])
 
 
print(solve())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	if k >= 10*8:
		return 1
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	for i in range(k):
		x,cnt,orig = heappop(a)
		heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
	return -(heappop(a)[0])
 
 
print(solve())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	if k >= 10**7:
		return 1
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	for i in range(k):
		x,cnt,orig = heappop(a)
		heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
	return -(heappop(a)[0])
 
 
print(solve())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	if k >= 30*2*10**5:
		return 1
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	for i in range(k):
		x,cnt,orig = heappop(a)
		heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
	return -(heappop(a)[0])
 
 
print(solve())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	slices = 0
	while slices < k:
		x,cnt,orig = heappop(a)
		if x == -1:
			return 1
		x = -x-1
		# print(x)
		if (orig+cnt)//(cnt+1) > x:
			if slices +(orig+x-1)//x >= k:
				return x+1
			else:
				cnt_t = (orig+x-1)//x
				slices += cnt_t - cnt
				heappush(a,(-x,cnt,orig))
		else:
			heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
			slices+=1
	return -(heappop(a)[0])


print(solve())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	slices = 0
	while slices < k:
		x,cnt,orig = heappop(a)
		if x == -1:
			return 1
		x = -x-1
		print(x)
		if (orig+cnt)//(cnt+1) > x:
			if slices +(orig+x-1)//x >= k:
				return x+1
			else:
				cnt_t = (orig+x-1)//x
				slices += cnt_t - cnt
				heappush(a,(-x,cnt,orig))
		else:
			heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
			slices+=1
	return -(heappop(a)[0])


print(solve())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import math
def solve():
	n , k= map(int, input().strip().split())
	a= [(-int(x),1,int(x)) for x in input().strip().split()]
	heapify(a)
	for i in range(k):
		x,cnt,orig = heappop(a)
		if x < 1:
			return 1
		heappush(a,(-((orig+cnt)//(cnt+1)),cnt+1,orig))
	return -(heappop(a)[0])


print(solve())

Submission status: Wrong Answer

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

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

minlen = 1
maxlen = 10**9

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

print(maxlen)

Submission status: Wrong Answer

Solution code:
# logs
import bisect
import math
k = int(input().split()[1])
# a = list(map(int, input().split()))
tmp = input().split()
a = [int(s) for s in tmp]
a.sort()
# print(a)
for i in range(k):
	x = a.pop()/2
	pos = bisect.bisect_right(a, x)
	a.insert(pos, x)
	# print(a)
print(math.ceil(a.pop()))

Submission status: Wrong Answer

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

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

print(r)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
right = 20000000000000
left = 0
while(right-left>1):
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count > K:
        left = mid
    else:
        right = mid
print(mid)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
right = maxA+1
left = 0
while(right-left>1):
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count > K:
        left = mid
    else:
        right = mid
print(mid)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
right = maxA+1
left = 0
while(right-left>1):
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count > K:
        left = mid
    elif count <= K:
        right = mid
print(mid)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
num = 0
right = maxA
left = 0
while(right-left>1):
    num = left+math.floor((right-left)*0.5)
    count = 0
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
    if count > K:
        left = num
    elif count <= K:
        right = num

print(num+1)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
xma=a[-1]
x=a[-1]/2
xmi=0
xo=-1
while abs(x-xo)>0.0001:
  k2=k
  for i in range(n):
      k2-=(a[i]//x)
  if k2<0:
      xo=x
      xmi=x
      x=(xma+x)/2
  else:
    xo=x
    xma=x
    x=x/2

print(math.ceil(x))

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
xma=a[-1]
x=a[-1]/2
xmi=0
xo=-1
while abs(x-xo)>0.0001:
  k2=k
  for i in range(n):
      k2-=math.ceil(a[i]/x)-1
  if k2<0:
      xo=x
      xmi=x
      x=(xma+x)/2
  else:
    xo=x
    xma=x
    x=x/2

print(math.ceil(x))

Submission status: Wrong Answer

Solution code:
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
xma=a[-1]
x=a[-1]//2
xmi=0
xo=-1
while abs(x-xo)>0.01:
  k2=k
  for i in range(n):
    j=1
    while a[i]/j>x:
      j+=1
      k2-=1
  if k2<0:
      xo=x
      xmi=x
      x=(xma+x)/2
  else:
    xo=x
    xma=x
    x=x/2
import math
print(math.ceil(x))

Submission status: Wrong Answer

Solution code:
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
xma=a[-1]
x=a[-1]//2
xmi=0
xo=-1
while abs(x-xo)>0.0001:
  k2=k
  for i in range(n):
    j=1
    while a[i]/j>x:
      j+=1
      k2-=1
  if k2<0:
      xo=x
      xmi=x
      x=(xma+x)/2
  else:
    xo=x
    xma=x
    x=x/2
import math
print(math.ceil(x))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
arr = list(map(int, input().split()))
def f(x):
    res = 0
    for i in range(N):
        res += arr[i]//x
    return res
left = 1
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: Wrong Answer

Solution code:
N, K = map(int, input().split())
arr = list(map(int, input().split()))
def f(x):
    res = 0
    for i in range(N):
        res += arr[i]//x
    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: Wrong Answer

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

ok = 1
ng = max(A) + 10

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

Submission status: Wrong Answer

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

ok = 1
ng = max(A)

while abs(ok - ng) > 1:
  mid = (ok + ng) // 2
  cnt = 0
  for a in A:
    cnt += (a - 1) // mid
  if cnt <= k:
    ng = mid
  else:
    ok = mid

print(ng)

Submission status: Wrong Answer

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 // middle
        if cnt <= K:
            right = middle
        else:
            left = middle
    print(right)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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)+1
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+sig)//2
  else:
    low=sig+1
    sig=(high+sig)//2
print(ans)

Submission status: Wrong Answer

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
        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: Wrong Answer

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 = 1
    g = 10**9
    mae = -1
    now = 1
    while now != mae:
        mae = now
        c = 0
        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: Wrong Answer

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 = 1
    g = 10**9
    mae = -1
    now = 1
    while now != mae:
        mae = now
        c = 0
        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: Wrong Answer

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 = 1
    g = 10**9
    mae = -1
    now = 1
    while now != mae:
        mae = now
        c = 0
        now = (s + g)//2
        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+1)

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys


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


N, K = acinput()
#A = np.array(sorted(acinput(), reverse=True))
A = np.array(acinput())


def bisect_search(f, l=-1, r=10**10):
    while r-l > 1:
        c = (l+r)//2
        if f(c):
            r = c
        else:
            l = c
    return c


def f(d):
    n = 0
    for tmp in np.ceil(A/d):
        # if tmp <= 1:
        #    break
        n += tmp-1
    return n <= K


d = bisect_search(f)

print(int(np.ceil(d)))

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys


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


N, K = acinput()
A = np.array(sorted(acinput(), reverse=True))


def bisect_search(f, l=-1, r=10**10):
    while r-l > 1:
        c = (l+r)//2
        if f(c):
            r = c
        else:
            l = c
    return c


def f(d):
    n = 0
    for tmp in np.ceil(A/d):
        if tmp <= 1:
            break
        n += tmp-1
    return n <= K


d = bisect_search(f)

print(int(np.ceil(d)))

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys


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


N, K = acinput()
A = np.array(sorted(acinput(), reverse=True))


def bisect_search(f, l=-1, r=10**10):
    while r-l > 1:
        c = (l+r)/2
        if f(c):
            r = c
        else:
            l = c
    return c


def f(d):
    n = 0
    for tmp in np.ceil(A/d):
        if tmp <= 1:
            break
        n += tmp-1
    return n <= K


d = bisect_search(f)

print(int(np.ceil(d)))

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys


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


N, K = acinput()
A = np.array(sorted(acinput(), reverse=True))


def bisect_search(f, l=-1, r=10**6):
    while r-l > 1:
        c = (l+r)/2
        if f(c):
            r = c
        else:
            l = c
    return c


def f(d):
    n = 0
    for tmp in np.ceil(A/d):
        if tmp <= 1:
            break
        n += tmp-1
    return n <= K


d = bisect_search(f)

print(int(np.ceil(d)))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=1
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: Wrong Answer

Solution code:

import numpy as np
import sys


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


N, K = acinput()
A = np.array(sorted(acinput(), reverse=True))


def bisect_search(f, l=0, r=10**6):
    while r-l >= 0.5:
        c = (l+r)/2
        if f(c):
            r = c
        else:
            l = c
    return c


def f(d):
    n = 0
    for tmp in np.ceil(A/d):
        if tmp <= 1:
            break
        n += tmp-1
    return n <= K


d = bisect_search(f, l=0, r=A[0])

print(int(np.ceil(d)))

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys


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


N, K = acinput()
A = np.array(sorted(acinput(), reverse=True))


def bisect_search(f, l=0, r=10**6):
    while abs(r-l) > 1:
        c = (l+r)/2
        if f(c):
            r = c
        else:
            l = c
    return c


def f(d):
    n = 0
    for tmp in np.ceil(A/d):
        if tmp <= 1:
            break
        n += tmp-1
    return n <= K


res = bisect_search(f, l=0.01, r=A[0]+1)

print(int(np.ceil(res)))

Submission status: Wrong Answer

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