Problem: 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.

Submission attempts (in order):
#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()))

A.sort(reverse=True)

def nibu(small,big):
    mid = (small+big)//2
#    k_list = [x//mid for x in A2]
    k_list = [x//mid for x in A]
    sum_k = sum(k_list)
    if sum_k <= K: 
        return small,mid 
    else:
        return mid,big 


if N==1 or K==0:
    ans = A[0]
else:    
#    All_length = sum(A)
#    KK = K+N-1

    lmin = 0
    
#    A2 = [x for x in A if x > lmin]
    
#    Kper1 = K//len(A2)
    

    lmax = A[1]
    
    while lmax - lmin >= 2:
        lmin, lmax = nibu(lmin,lmax)
    
    ans = lmax
    
print(ans)

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

A.sort(reverse=True)

def nibu(small,big,KK,AA):
    mid = (small+big)//2
    k_list = [(x+1)//mid for x in AA]
    sum_k = sum(k_list)
    if sum_k <= KK: 
        return small,mid 
    else:
        return mid,big 


if K==0:
    ans = A[0]
else:    
    lmin = 0
    lmax = A[0]
    
    while lmax - lmin >= 2:
        lmin, lmax = nibu(lmin,lmax,K,A)
    
    ans = lmax
    
print(ans)

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

A.sort(reverse=True)

All_length = sum(A)
KK = K+N-1
lm = All_length/KK

k_list = [int(Ai//lm) for Ai in A]
X_list = [Ai%lm for Ai in A]

sum_k = sum(k_list)
res_cut = KK-sum_k

zero_k = 0
for i in range(1,N+1):
    if k_list[-i] == 0:
        zero_k +=1
    else:
        break

if res_cut > 0:
    ans_kouho = []
    for i in range(-zero_k,0):
        ans_kouho.append(X_list[i])
    for i in range(res_cut):
        for j in range(N-zero_k):
            ans_kouho.append((X_list[j]-i*lm)/k_list[j])
    
    ans_kouho.sort(reverse=True)
    ans = ans_kouho[res_cut] + lm
    ans = int(ans)+1
else:
    ans = int(lm)+1
print(ans)

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

A.sort(reverse=True)

def nibu(small,big,KK,AA):
    mid = (small+big)//2
    k_list = [(x-1)//mid for x in AA]
    sum_k = sum(k_list)
    if sum_k <= KK: 
        return small,mid 
    else:
        return mid,big 


if K==0:
    ans = A[0]
else:    
    lmin = 0
    lmax = A[0]
    
    while lmax - lmin >= 2:
        lmin, lmax = nibu(lmin,lmax,K,A)
    
    ans = lmax
    
print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted