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: Time Limit Exceeded

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))
    
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(1000):
    mid=(ok+ng)/2
    if check(mid):
        ok=mid
    else:
        ng=mid
    # print(ok,ng)
print(ceil(ok))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
import copy
a = copy.deepcopy(p)
for i in range(n):
    a[i] = [-a[i],0,i]
import heapq as hp
hp.heapify(a)
for i in range(k):
    s = hp.heappop(a)
    u = [s[0]/2,s[1]+1,s[2]]
    hp.heappush(a, u)
ans = 0
for i in range(n):
    ans = max(-(-p[a[i][2]]//(a[i][1]+1)),ans)
print(ans)

Submission status: Time Limit Exceeded

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, val=0, l=0, r=10**6):

    # is_increase=(f(r)-f(l))>=0

    eps = 10**(-5)
    while True:

        c = (l+r)/2
        if f(c) == val:
            return c
        # if f(c)-val < eps:
        #    return c

        if f(c) < val:
            r = c

        else:
            l = c

        if l >= r:
            return False


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

    return n


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

if res == False:
    res = A[-1]
    print(res)
    sys.exit()

d = res
n = np.ceil(np.array(A)/d)


d2 = [0]*(N)
for i in range(N):
    d2[i] = A[i]/n[i]

print(int(np.ceil(max(d2))))

Submission status: Time Limit Exceeded

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, val=0, l=0, r=10**6):

    # is_increase=(f(r)-f(l))>=0

    eps = 10**(-5)
    while True:

        c = (l+r)/2
        if f(c) == val:
            return c
        # if f(c)-val < eps:
        #    return c

        if f(c) < val:
            r = c

        else:
            l = c

        if l >= r:
            return False


def f(d):
    n = 0
    i = 0
    NN = A/d
    while True:
        tmp = NN[i]
        if tmp < 1:
            break
        n += np.ceil(tmp)-1
        i += 1
        if i >= len(A):
            break
    return n


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

if res == False:
    res = A[-1]
    print(res)
    sys.exit()

d = res
n = np.ceil(np.array(A)/d)


d2 = [0]*(N)
for i in range(N):
    d2[i] = A[i]/n[i]

print(int(np.ceil(max(d2))))

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
import sys


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


N, K = acinput()
A = sorted(acinput(), reverse=True)


def bisect_search(f, val=0, l=0, r=10**6):

    # is_increase=(f(r)-f(l))>=0

    eps = 10**(-5)
    while True:

        c = (l+r)/2
        if f(c) == val:
            return c
        # if f(c)-val < eps:
        #    return c

        if f(c) < val:
            r = c

        else:
            l = c

        if l >= r:
            return False


def f(d):
    n = 0
    i = 0
    while True:
        tmp = A[i]/d
        if tmp < 1:
            break
        n += np.ceil(tmp)-1
        i += 1
        if i >= len(A):
            break
    return n


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

if res == False:
    res = A[-1]
    print(res)
    sys.exit()

d = res
n = np.ceil(np.array(A)/d)


d2 = [0]*(N)
for i in range(N):
    d2[i] = A[i]/n[i]

print(int(np.ceil(max(d2))))

Submission status: Time Limit Exceeded

Solution code:
import numpy
import math

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

cut = [0] * n
dmy = [0] * n

while k:
    
    i = 0
    for a, b in zip(A, cut):
        c = a / (b + 1)
        dmy[i] = c
        i += 1      
    cut[numpy.argmax(dmy)] += 1
    
    k -= 1
  
i = 0
for a, b in zip(A, cut):
        c = a / (b + 1)
        dmy[i] = c 
        i += 1

print(math.ceil(max(dmy)))

Submission status: Time Limit Exceeded

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

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

hp = []

for log in A:
    heapq.heappush(hp, (-log, log, 1))

for i in range(K):
    cur_length, length, count = heapq.heappop(hp)
    cur_length = -cur_length
    new_length = length / (count + 1)
    heapq.heappush(hp, (-new_length, length, count + 1))

print(ceil(-hp[0][0]))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while R-L > 1:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = int(X)+1
    else:
        L = int(X)
print(int(R))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = 0
R = max(A)
while int(R)-int(L) > 0:
    X = (L+R)/2
    m = 0
    for i in range(N):
        c = A[i]/X
        if c == int(c):
            m += int(c) - 1
        else:
            m += int(c)
    if m <= K:
        R = X
    else:
        L = X
print(int(R)+1)

Submission status: Time Limit Exceeded

Solution code:
import math

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

ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

cnt = 0


while True:
    cnt += 1
    target_a = [ceil(x/target_length)-1 for x in a]
    if sum(target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


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

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

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:# sum == K
            r = test

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

    print(int(l)+1)

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


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

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

        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test
    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


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

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

        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test
    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += (a - eps) // int(l)
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


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

    l = 0
    r = 10**9
    eps = 1e-8
    while int(l) != int(r):
        test = (l + r) / 2
        sum = 0
        for a in A:
            val1 = a / test
            val2 = a // test
            if val1 == val2:
                sum += val2 - 1
            else:
                sum += val2
        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test
    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += (a - eps) // int(l)
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


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

    l = 0
    r = 10**9
    eps = 1e-8
    while int(l) != int(r):
        test = (l + r) / 2
        sum = 0
        for a in A:
            if a / test == a //test:
                sum += a // test - 1
            else:
                sum += a // test
        if sum > K:
            l = test
        elif a < K:
            r = test
        else:# sum == K
            r = test
    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += (a - eps) // int(l)
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return deque(lis[:now+1] + [item] + lis[now+1:])
  

C = sum(cut)
res = min(K - C, N)
length = length[:res+1]
length = deque(length)
for k in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  length = nibun_insert(list(length), list(a))
  length.pop()

print(math.ceil(length.popleft()[0]))

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return lis[:now+1] + [item] + lis[now+1:]
  

C = sum(cut)
res = min(K - C, N)
length = length[:res+1]
for k in range(res):
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
  if length[0][0] < length[1][0]:
    length = nibun_insert(length[1:], length[0])
  length = length[:-1]

print(math.ceil(length[0][0]))

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return lis[:now+1] + [item] + lis[now+1:]
  

C = sum(cut)
res = min(K - C, N)
length = length[:res+1]
for k in range(res):
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
  if length[0][0] < length[1][0]:
    length = nibun_insert(length[1:], length[0])

   
print(math.ceil(length[0][0]))

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return lis[:now+1] + [item] + lis[now+1:]
  

C = sum(cut)
res = min(K - C, 10**6)
length = length[:res+1]
for k in range(res):
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
  if length[0][0] < length[1][0]:
    length = nibun_insert(length[1:], length[0])

   
print(math.ceil(length[0][0]))

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from math import ceil, floor

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

def isOk(x):
    cnt = 0
    for a in A:
        cnt += floor(Fraction(a, x))
    return cnt <= K

ok = max(A)
ng = 0
for _ in range(50):
    mid = Fraction(ok + ng, 2)
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ceil(ok))

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from math import ceil, floor

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

def isOk(x):
    cnt = 0
    for a in A:
        cnt += floor(Fraction(a, x))
    return cnt <= K

ok = max(A)
ng = 0
for _ in range(100):
    mid = Fraction(ok + ng, 2)
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ceil(ok))

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return lis[:now+1] + [item] + lis[now+1:]
  

C = sum(cut)
res = K - C
length = length[:res+1]
for k in range(res):
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
  if length[0][0] < length[1][0]:
    length = nibun_insert(length[1:], length[0])

   
print(math.ceil(length[0][0]))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
num_arr = [1]*n
length_arr = []
for i in arr:
  length_arr += [i]

for i in range(k):
  max_idx = length_arr.index(max(length_arr))
  tmp = num_arr[max_idx] + 1
  num_arr[max_idx] = tmp
  length_arr[max_idx] = arr[max_idx] // tmp + 1

result_int = max(length_arr) - 0.0001
print(int(result_int//1 + 1))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
num_arr = [1]*n
length_arr = []
for i in arr:
  length_arr += [i]

for i in range(k):
  max_idx = length_arr.index(max(length_arr))
  tmp = num_arr[max_idx] + 1
  num_arr[max_idx] = tmp
  length_arr[max_idx] = arr[max_idx] / tmp

result_int = max(length_arr) - 0.0001
print(int(result_int//1 + 1))

Submission status: Time Limit Exceeded

Solution code:
import os
import sys
from io import BytesIO, IOBase
from math import ceil

def possible(logs, k, ans):
    for l in logs:
        k -= ceil(l/ans) - 1
    return k>=0


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

    l = 1
    r = max(logs) + 1

    while l <= r:
        mid = (l + r)//2
        if possible(logs, k, mid):
            r = mid
        else:
            l = mid + 1
    print(l)




        




































# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
 
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

lb, ub = 0, max(a)
while ub - lb > 1:
    mid = (ub + lb) // 2

    cnt = 0
    for i in range(n):
        cnt += a[i] // mid
        if a[i] % mid != 0:
            cnt += 1
        cnt -= 1

    if cnt <= k:
        ub = mid
    else:
        lb = mid

print(ub)

Submission status: Time Limit Exceeded

Solution code:
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    K_i=[int(A[i]/sum(A)*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
from math import ceil
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
    print(max(A))
    exit()

A=sorted(A)
# 最小値で二分探索 してまだ行けるかどうか
# 回数で二分探索
left=0
right=max(A)

ans=float("INF")
pre=ans
flag=False
count=0
while True:
    now=0
    mid=(left+right)/2
    idx=bisect_right(A, mid)
    for i in range(idx, N):
        now+=ceil(A[i]/mid)-1
    if now==K:
        if ans!=float("INF"):
            if ans==ceil(mid):
                flag=True
        ans=min(ans, ceil(mid))
        right=mid
        
        #if flag:
        #    break
        pre=ans
    if now>K:
        left=mid
        pre=mid
    if now<K:
        ans=min(ans, ceil(mid))
        right=mid
        pre=mid
    count+=1
    if count>=10**3:
        break
    


if ans==float("INF"):
    ans=max(A)
print(ceil(ans))

Submission status: Time Limit Exceeded

Solution code:
import math
import heapq
N, K = map(int, input().split())
A = sorted([(-int(i), int(i), 1) for i in input().split()])
heapq.heapify(A)  # リストhqのheap化

for _ in range(K):
    _, L, T = heapq.heappop(A)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    heapq.heappush(A, (-L/(T+1), L, T+1))  # heap化されたリストhqに要素xを追加
_, L, T = heapq.heappop(A)
print(math.ceil(L/T))

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = map(int, input().split())
A = sorted([(int(i), 1) for i in input().split()], key=lambda x: x[0])


for _ in range(K):
    L, T = A.pop(-1)
    A.append((L*T/(T+1), T+1))
    A.sort(key=lambda x: x[0])
print(math.ceil(A[-1][0]))

Submission status: Time Limit Exceeded

Solution code:
import math
import heapq
N, K = map(int, input().split())
A = sorted([(-int(i), 1) for i in input().split()])
heapq.heapify(A)  # リストhqのheap化

for _ in range(K):
    L, T = heapq.heappop(A)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    heapq.heappush(A, (L*T/(T+1), T+1))  # heap化されたリストhqに要素xを追加
print(math.ceil(-heapq.heappop(A)[0]))

Submission status: Time Limit Exceeded

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) - 1
    return cnt

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

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
    if mid == 0:
        print(1)
        break

Submission status: Time Limit Exceeded

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) - 1
    return cnt

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

if mid == 0 or mid == 1:
    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
    if mid == 0:
        print(1)
        break

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = 0
q = max(a)
r = q
t = [0,q]
i = 10
while(t[0]+1 != t[1]):
    p *= 0
    for i in range(n):
        if(a[i] > q):
            x = 2
            while((a[i]/x) > q):
                x += 1
            p += x-1
        if(p > k):
            break
    r = max(1,r//2)
    if(p > k):
        t[0] = max(t[0],q)
        q += r
    else:
        t[1] = min(t[1],q)
        q -= r
    i -= 1
print(t[1])

Submission status: Time Limit Exceeded

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 k>0 and 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