TnT/Multi_CodeNet4Repair huggingface dataset:
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):

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]








n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    for i in range(n):
        ans += math.ceil(li[i]/x) - 1
    if ans <= k:
        return True
    else:
        return False
left = -1
right = 10**9+1
while right != left + 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)




import math

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]








n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    for i in range(n):
        ans += math.ceil(li[i]/x) - 1
    if ans <= k:
        return True
    else:
        return False
left = 0
right = 10**9+1
while abs(left-right) > 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)


Verdicts: Runtime Error

Accepted
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 math

def is_ok(A, x, K):
    cut_count = 0
    for number in A:
        cut_count += (math.ceil(number / x)) - 1
    return cut_count <= K

A = []
# N = int(input())
# K = int(input())
ans = 0

l = 0
r = 10 ** 9

# for _ in range(N):
#     A.append(int(input()))

N = 10
K = 10
A = [158260522,877914575,602436426,24979445,861648772,623690081,433933447,476190629,262703497,211047202]

while r - l > 1:
    print("r = " + str(r) + ", l = " + str(l))
    x = (r + l) // 2
    if is_ok(A, x, K):
        r = x       
    else:
        l = x
      
print(r)

def is_ok(A, x, K):
    cut_count = 0
    for number in A:
        cut_count += (number // x) - 1
    return cut_count <= K

A = []
N = int(input())
K = int(input())
ans = 0

l = 0
r = 10 ** 9

for _ in range(N):
    A.append(int(input()))

while r - l > 1:
    x = (r + l) // 2
    if is_ok(A, x, K):
        r = x       
    else:
        l = x
      
print(r)

import math

def is_ok(A, x, K):
  cut_count = 0
  for number in A:
    cut_count += (math.ceil(number / x)) - 1
  return cut_count <= K

A = []
N = int(input())
K = int(input())
ans = 0

l = 0
r = 10 ** 9

for _ in range(N):
  A.append(int(input()))

while r - l > 1:
  x = (r + l) // 2
  if is_ok(A, x, K):
    r = x
  else:
    l = x
      
print(r)

import math

def is_ok(A, x, K):
  cut_count = 0
  for number in A:
    cut_count += (math.ceil(number / x)) - 1
  return cut_count <= K

A = []
[N, K] = input().split()
N = int(N)
K = int(K)
A = input().split()
ans = 0

l = 0
r = 10 ** 9

for i in range(N):
  A[i] = int(A[i])

while r - l > 1:
  x = (r + l) // 2
  if is_ok(A, x, K):
    r = x
  else:
    l = x
      
print(r)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
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):
from math import ceil
from heapq import heapify, heappop, heappush

N, K, *A = map(int, open(0).read().split())

t = sum(A) / K
a = [None] * len(A)
for i in A:
    k = max(ceil(i / t), 1)
    a.append((-i / k, i, k))

heapify(a)
for _ in range(K):
    i, j, k = heappop(a)
    k += 1
    i = -(j / k)
    heappush(a, (i, j, k))
print(ceil(heappop(a)[0] * -1))


from math import ceil

N, K, *A = map(int, open(0).read().split())

def is_ok(n):
    t = 0
    for a in A:
        if a <= n:
            continue
        t += ceil(a / n) - 1
    return t <= K

ok = 1000000000
ng = 0.0000000001
while abs(ng - ok) > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(ceil(ok))


Verdicts: Runtime Error

Accepted
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):
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
else:
    ans=0
    d=round(max(a)*k/sum(a))
    print(-(-max(a)//(d+1)))

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
else:
    ans=0
    for i in a:
        d=-(-k*i//sum(a))
        if d>0:
            ans=max(ans,-(-i//(d+1)))
        else:
            ans=max(ans,i)
    print(ans)

def check(List,mid):
    tmp=0
    for l in List:
        tmp+=(-(-l//mid)-1)
    return tmp

n,k=map(int,input().split())
a=list(map(int,input().split()))
lo=0
hi=max(a)+1

while hi - lo > 1:
    mid=(lo+hi)//2
    if check(a,mid)<=k:
        hi=mid
    else:
        lo=mid

print(hi)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
n, k = map(int, input().split())
a = list(map(int, input().split()))
low = 0
top = max(a) + 1

while top - low > 1:
  mid = (top + low) // 2
  cnt = 0
  for i in range(n):
    if a[i] % mid == 0:
      cnt += a[i] // mid
    else:
      cnt += (a[i] // mid) + 1
  if cnt <= k:
    top = mid
  else:
    low = mid
print(low)


n, k = map(int, input().split())
a = list(map(int, input().split()))
low = min(a)
top = max(a)

while top - low > 1:
  mid = (top + low) // 2
  cnt = 0
  for i in range(n):
    cnt += (a[i] + 1) // mid
  if cnt <= k:
    top = mid
  else:
    low = mid
print(low)

n, k = map(int, input().split())
a = list(map(int, input().split()))
low = 0
top = max(a) + 1

while top - low > 1:
  mid = (top + low) // 2
  cnt = 0
  for i in range(n):
    if a[i] % mid == 0:
      cnt += (a[i] // mid) - 1
    else:
      cnt += a[i] // mid
  if cnt <= k:
    top = mid
  else:
    low = mid
print(low)


n, k = map(int, input().split())
a = list(map(int, input().split()))
low = 0
top = max(a) + 1

while top - low > 1:
  mid = (top + low) // 2
  cnt = 0
  for i in range(n):
    if a[i] % mid == 0:
      cnt += (a[i] // mid) - 1
    else:
      cnt += a[i] // mid
  if cnt <= k:
    top = mid
  else:
    low = mid
print(top)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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 math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(revese=True)
for i in range(k):
  t=max(a)
  a.insert(0,t/2)
  a.remove(t)
print(math.ceil(max(a)))

n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=0,max(a)
def test(x):
  num=0
  for i in a:
    num+=i//x
    if i%x==0:
      num-=1
  if num<=k:
    return num
while r-l>1:
  mid=(l+r)//2
  if test(mid):
    r=mid
  else:
    l=mid
print(r)

Verdicts: Runtime Error

Accepted
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):
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])

from math import modf
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]
c = k - sum(int(a/t)-1 for a in A)
X = []
for a in A:
    X.append(ceil(a / ceil(a/t)))
    X.append(ceil(a / int(a/t)))
X.sort()
print(X[-c-1])

class BisectSearch:
    def __init__(self, f, l=0, r=10**9):
        self.f = f
        self.l = l
        self.r = r
    def __call__(self, dist):
        f = self.f
        l = self.l
        r = self.r
        if dist <= f(l):
            return l
        if f(r) <= dist:
            return r
        while r-l > 1:
            n = (r+l) // 2
            if f(n) <= dist:
                l = n
            else:
                r = n
        return l, r

n, k, *A = map(int, open(0).read().split())
print(BisectSearch(lambda x:k+1-sum(ceil(a/x)-1 for a in A), l=1)(0)[1])

from math import modf
n, k, *A = map(int, open(0).read().split())
A.sort(reverse=1)
t = sum(A) / (n+k)
B = [(modf(a/t - 1)[0], modf(a/t - 1)[1], a) for a in A if a/t > 1]
B.sort(reverse=1)
c = k - sum(int(y) for x, y, z in B)
ans = 0
X = []
for i, (_, y, z) in enumerate(B):
    X.append(ceil(z / (y+2)))
    X.append(ceil(z / (y+1)))
X.sort()
print(X[-c-1])

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

from math import ceil
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])

from math import ceil
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[sum(int(a/t)-1 for a in A) -k-1])

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
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):
n,k = map(int,input().split())
a = list(map(int,input().split()))
def check(t):
  ans = 0
  for aa in a:
    if aa > t:
      ans += aa//t
max = 10**9
min = 0
while max-min>1:
  mid = (max+min)/2
  if check(mid):
    max = mid
  else:
    min = mid
print(max)

import sys
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k ==0:
  print(max(a))
  sys.exit()
def check(t):
  ans = 0
  if t==0:
    return False
  for aa in a:
    if aa > t:
      ans += aa//t
  return ans <= k
max = 10**9+1
min = 0
while max-min>1:
  mid = (max+min)//2
  if check(mid):
    max = mid
  else:
    min = mid
print(math.ceil(max))

Verdicts: Wrong Answer

Accepted
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):
n,k = map(int,input().split())
a = list(map(int,input().split()))

leq,high = 0,1e10
while high-leq > 1:
  l = int((leq+high)/2)
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  print(l,cnt)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)

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

leq,high = 0,1e10
while high-leq > 1:
  l = int((leq+high)/2)
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  print(l,cnt)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)

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

leq,high = 0,1e10
while high-leq > 1:
  l = int((leq+high)/2)
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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 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
count = 0
num = right
for i in range(len(A)):
    count += math.ceil(A[i]/num)-1
if count!=K:
    num = left
    count = 0
    for i in range(len(A)):
        count += math.ceil(A[i]/num)-1
print(num)


N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
mid = (left+right)//2
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
    elif count > K:
        left = mid
    else:
        flag = False
print(mid)


import math
N, K = map(int, input().split())
A=list(map(int,input().split()))
maxA = max(A)
right = maxA
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)


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)


N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = -1
flag = True
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
    elif count > K:
        left = mid
    else:
        flag = False
print(mid)


N, K = map(int, input().split())
A=list(map(int,input().split()))
A.sort()
right = A[-1]+1
left = 0
flag = True
mid = (left+right)//2
minN = right
result = mid
while right-left>1 and flag:
    mid = (left+right)//2
    count = 0
    for i in A:
        count += (i-1)//mid
    if count <= K:
        right = mid
        if minN>mid:
            minN = mid
            result = mid
    elif count > K:
        left = mid
print(result)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
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):
n,k =  map(int,input().split())
A = list(map(int,input().split()))

l = min(A)//(k+1) 
r = max(A)
m = (l+r)//2+1

while 1:
    
    m = (l+r)//2
    
    
    
    # A_long = A[A>m]
    n= sum( [A[i]//m - A[i]%m==0 for i in range(len(A)) ] )
    
    # print(l,m,r,n)
    
    if n<=k:
        if r==m:
            break
        r=m-1
    else:
        if l==m:
            m=m+1
            break
        l=m+1
        

        
print(m)
    

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

l = min(A)//(k+1) 
r = max(A)
m = (l+r)//2+1

while 1:
    
    m = (l+r)//2
    
    
    
    # A_long = A[A>m]
    n= sum( [  int((A[i]-0.1)//(m)) for i in range(len(A)) ] )
    
    print(l,m,r,n)
    
    if n<=k:
        if r==m:
            break
        r=m-1
    else:
        if l==m:
            m+=1
            break
        l=m+1
        

        
print(m)


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

l = min(A)//(k+1) 
r = max(A)
m = (l+r)//2+1

while 1:
    
    m = (l+r)//2
    
    
    
    # A_long = A[A>m]
    n= sum( [A[i]+0.1//m for i in range(len(A)) ] )
    
    # print(l,m,r,n)
    
    if n<=k:
        if r==m:
            break
        r=m-1
    else:
        if l==m:
            m=m+1
            break
        l=m+1
        

        
print(m)
    

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

l = min(A)//(k+1) 
r = max(A)
m = (l+r)//2+1

while 1:
    
    m = (l+r)//2
    
    if m==0:
        m=1
        break
    
    
    
    # A_long = A[A>m]
    n= sum( [  int((A[i]-0.1)//(m)) for i in range(len(A)) ] )
    
    # print(l,m,r,n)
    
    if n<=k:
        if r==m:
            break
        r=m-1
    else:
        if l==m:
            m+=1
            break
        l=m+1
        

        

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

l = min(A)//(k+1) 
r = max(A)
m = (l+r)//2+1

while 1:
    
    m = (l+r)//2
    if m==0:
        m=1
        break

    
    
    
    # A_long = A[A>m]
    n= sum( [  int((A[i]-0.1)//(m)) for i in range(len(A)) ] )
    
    # print(l,m,r,n)
    
    if n<=k:
        if r==m:
            break
        r=m-1
    else:
        if l==m:
            m+=1
            break
        l=m+1
        

        
print(m)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
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):
input = open("input.in").readline

def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    
    l,r = 0, max(A)
    while l < r-1:
        mid = l + (r-l)//2
        cnt = 0
        for a in A:
            cnt+= a//mid
            
        if cnt <= K:
            r = mid
        else:
            l = mid
    print(r)
    
main()

import sys
input = sys.stdin.readline

def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    
    l,r = 0, max(A)
    while l < r-1:
        mid = (l+r)//2
        cnt = 0
        for a in A:
            if a % mid:
                cnt+= a//mid
            else:
                cnt += a//mid - 1
            
        if cnt <= K:
            r = mid
        else:
            l = mid
    print(r)
    
main()

Verdicts: Runtime Error

Accepted
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):
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
ok = 0
ng = 10**10


def judge(l):
    cnt = 0
    for aa in a:
        if aa <= l:
            break
        while aa > l:
            aa /= 2
            cnt += 1
    return cnt <= k


while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if judge(mid):
        ok = mid
    else:
        ng = mid
print(ok)


from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
ok = 10**10
ng = 0


def judge(x):
    cnt = 0
    for aa in a:
        cnt += (x + aa - 1) // x - 1
        # print(cnt)
    return cnt <= k


# print(judge(4))
# print(judge(5))
# print(judge(3))

while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if judge(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Verdicts: Wrong Answer

Accepted
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):
def count(N,K,mid,a):
    cnt = 0
    for i in range(N):
        cnt = a[i]//mid
    if cnt > K:
        return False
    else:
        return True

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    low = 1
    high = 10**9
    mid = (low+high)//2

    while high > low+1:
        if count(N,K,mid,a):
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    if count(N,K,low,a):
        print(high)
    else:
        print(low)

main()

import math

def count(N,K,mid,a):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(a[i]/mid-1)
    if cnt > K:
        return False
    else:
        return True

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    low = 1
    high = 10**9+1
    mid = (low+high)//2

    while high > low+1:
        if count(N,K,mid,a):
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    if count(N,K,low,a):
        print(low)
    else:
        print(high)

main()

Verdicts: Wrong Answer

Accepted
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):
def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if sum([(i-1)//x for i in a])<=k: r=m;
    else: l=m;
  print(r)

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  main()

def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if sum([(i-1)//m for i in a])<=k: r=m;
    else: l=m;
  print(r)

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  main()

Verdicts: Runtime Error

Accepted
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):
N, K=map(int,input().split())
A=list(map(int,input().split()))

def judge(ans,K,A):
    cut=0
    for i in range(len(A)):
        cut+=(A[i]-1)//ans
    if cut>K:
        return False
    else:
        return True


ansp=max(A)
ansm=min(A)
ans=(ansp+ansm)//2
d=1
while ansp-ansm>d:
    
    if judge(ans,K,A):
        ansp=ans
        
    else:
        ansm=ans
        
    ans=(ansp+ansm)//2
print(ansp)

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

def judge(ans,K,A):
    cut=0
    for i in range(len(A)):
        cut+=A[i]//ans
    if cut>K:
        return False
    else:
        return True


ansp=max(A)
ansm=min(A)
ans=(ansp+ansm)//2
d=1
while ansp-ansm>d:
    
    if judge(ans,K,A):
        ansp=ans
        
    else:
        ansm=ans
        
    ans=(ansp+ansm)//2
print(ansp)

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

def judge(ans,K,A):
    cut=0
    for i in range(len(A)):
        cut+=int(A[i]/int(ans+1))
    if cut>K:
        return False
    else:
        return True


ansp=max(A)
ansm=min(A)
ans=int((ansp+ansm)/2+1)
while True:
    
    if judge(ans,K,A):
        ansp1=((ansp+ans)/2)
        if ansp1==ansp:
            break
        else:
            ansp=ansp1
    else:
        ansm1=((ans+ansm)/2)
        if ansm1==ansm:
            break
        else:
            ansm=ansm1
    ans=(ansp+ansm)/2
if ans-int(ans)<0.00000001:
    print(int(ans))
else:
    print(int(ans)+1)

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

def judge(ans,K,A):
    cut=0
    for i in range(len(A)):
        cut+=(A[i]-1)//ans
    if cut>K:
        return False
    else:
        return True


ansp=max(A)
ansm=0
ans=(ansp+ansm)//2
d=1
while ansp-ansm>d:
    
    if judge(ans,K,A):
        ansp=ans
        
    else:
        ansm=ans
        
    ans=(ansp+ansm)//2
print(ansp)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
from math import ceil
n,k = map(int,input().split())
a = list(map(int,input().split()))

print(n,k,a)

def cut(x):
  t = 0
  for i in a:
    if i <= x:
      continue
    t += ceil(i / x) - 1
  return t <= k

l,r=0,10**9
while l+1 < r:
  x = l + (r-l)//2
  if cut(x):
    r = x
  else:
    l = x
print(r)

from math import ceil
n,k = map(int,input().split())
a = list(map(int,input().split()))

def cut(x):
  t = 0
  for i in a:
    if i <= x:
      continue
    t += ceil(i / x) - 1
  return t <= k

l,r=0,10**9
while l+1 < r:
  x = l + (r-l)//2
  if cut(x):
    r = x
  else:
    l = x
print(r)

Verdicts: Wrong Answer

Accepted
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 math

def main():
    _, k = map(int, input().split())
    arr = list(map(int, input().split()))
    print(arr)
    l, r = 1, 1000000000
    while l < r:
        m = (l + r) // 2
        cnt = 0
        for val in arr:
            cnt += math.ceil(val / m) - 1
        if cnt > k:
            l = m + 1
        else:
            r = m
    print(l)
  
if __name__ == '__main__':
    main()

import math

def main():
    _, k = map(int, input().split())
    arr = list(map(int, input().split()))
    l, r = 1, 1000000000
    while l < r:
        m = (l + r) // 2
        cnt = 0
        for val in arr:
            cnt += math.ceil(val / m) - 1
        if cnt > k:
            l = m + 1
        else:
            r = m
    print(l)
  
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
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):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
s = sum(a)
x = [0]*n
y = 0
for i in range(n):
    y = int(a[i]/s*k)
    x[i] = [i, (a[i]/s*k)%1, y]

x.sort(key= lambda val : val[1],reverse=True)
for i in range(k-y):
    x[i][2] += 1
ans = 0
z = 0
for i in range(n):
    ans = max(ans, a[x[i][0]-1]/(x[i][2]+1))
    z += x[i][2]
print(int(-(-ans//1)))

def is_ok(arg):
    
    c = 0
    for x in a:
        c += -(-x//arg) - 1
    return c <= k

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n,k = map(int,input().split())
a = list(map(int,input().split()))
print(meguru_bisect(0,10**9+1))

Verdicts: Runtime Error

Accepted
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):
n,k=map(int,input().split())
a=list(map(int,input().split()))
tmax=max(a)
tmin=0
t=(tmax+tmin)//2
import math
ans=tmax
if k==0:
  print(tmax)
else:
  while True:
    s=0
    for i in range(n):
      s=s+math.ceil(a[i]/t)-1
    if k>=s:
      ans=min(math.ceil(t),math.ceil(ans))
      tmax=t
      t=(tmin+t)//2
    else:
      tmin=t
      t=(t+tmax)//2
    if tmax-tmin<0.01:
      break
  print(ans)

n,k=map(int,input().split())
a=list(map(int,input().split()))
tmax=max(a)
tmin=0
import math
ans=tmax
if k==0:
  print(tmax)
else:
  while True:
    t=(tmax+tmin)//2
    if abs(tmax-tmin)<=1:
      break
    s=0
    for i in range(n):
      s=s+math.ceil(a[i]/t)-1
    if k>=s:
      ans=min(math.ceil(t),ans)
      tmax=t
    else:
      tmin=t
  print(ans)

Verdicts: Runtime Error

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

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(a / i) - 1
    if su <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    
    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))

Verdicts: Runtime Error

Accepted
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 math

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

def isOK(minVal):
	tmpK=0
	for a in A:
		
		tmpK+=((-(-a//minVal))-1)

	if tmpK <= K:
		return True
	else:
		return False

ok = max(A)
ng = 0

while (math.ceil(ok) != math.ceil(ng)):
	mid = (ok+ng) / 2
	if isOK(mid):
		ok = mid
	else:
		ng = mid
	print(ok,ng)

print(math.ceil(ok))

import numpy as np
import math

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

def isOK(minVal):
	tmpK=0
	for a in A:
		
		tmpK+=((-(-a//minVal))-1)

	if tmpK <= K:
		return True
	else:
		return False

ok = max(A)
ng = 0

while (math.ceil(ok) != math.ceil(ng)):
	mid = (ok+ng) / 2
	if isOK(mid):
		ok = mid
	else:
		ng = mid
	#print(ok,ng)

print(math.ceil(ok))

Verdicts: Wrong Answer

Accepted
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 math

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

ng_len = 1
ok_len = 1000000000


def possible_len(length: int, log: list, k: int):
    count = 0
    for i in range(N):
        count += math.ceil(log[i] / length) - 1
    if count <= k:
        return True
    else:
        return False


while ok_len - ng_len > 1:
    mid = (ng_len + ok_len) // 2
    if possible_len(mid, logs, K):
        ok_len = mid
    else:
        ng_len = mid



#     print(ng_len)
# else:
    print(ok_len)


import math

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

ng_len = 0
ok_len = 1000000000


def possible_len(length: int, log: list, k: int):
    count = 0
    for i in range(N):
        count += math.ceil(log[i] / length) - 1
    if count <= k:
        return True
    else:
        return False


while ok_len - ng_len > 1:
    mid = (ng_len + ok_len) // 2
    if possible_len(mid, logs, K):
        ok_len = mid
    else:
        ng_len = mid

print(ok_len)


Verdicts: Wrong Answer

Accepted
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 math
N,K = map(int,input().split())
cs = list(map(int, input().split()))
ma = max(cs)
mi = 0
rgl = math.ceil(math.log2(ma))
rt = ma+1
def counter(ch,mo):
  rt =math.ceil(ch/mo)
  return rt-1 if rt > 0 else 0

for _ in range(rgl):
  cnt = 0
  for c in cs:
    cnt+=counter(c,ma)
  if cnt <= K and ma < rt:
    rt = ma
    ma = math.ceil((ma+mi)/2)
  else:
    tmp = ma
    ma += math.ceil((ma-mi)/2)
    mi = tmp

print(rt)

import math
N,K = map(int,input().split())
cs = list(map(int, input().split()))
high = max(cs) + 1  
low = 0  
 
while high - low > 1:
  x = (high - low) // 2 + low
  cnt = 0
  for a in cs:
    cnt += math.ceil(a/x) - 1
 
  if cnt <= K:  # OK
    high = x
  else:
    low = x
print(high)


Verdicts: Wrong Answer

Accepted
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):
N, K = map(int, input().split())
a = list(map(int, input().split()))
max_a = 10**9
min_a = 0

while max_a-min_a>1:
    count = K
    mean_a = (max_a+min_a)//2
    
    for i in range(N):
        if a[i]==mean_a: continue
        count -= -a[i]//mean_a
    if count >= 0:
        max_a = mean_a
    else:
        min_a = mean_a

print(max_a)

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

max_l = 10**9
min_l = 0
while max_l - min_l != 1:
    count = 0
    mean = (max_l+min_l)//2
    for i in range(n):
        count += -(-a[i]//mean)-1
    if count <= k:
        max_l = mean
    else:
        min_l = mean
print(max_l)

Verdicts: Wrong Answer

Accepted
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):
from math import ceil

def check(A,N,i,K):
    cnt=0
    for j in range(N):
        cnt+=ceil(A[j]/i)-1
    if cnt<=K:
        return 1
    else:
        return -1

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
M=A[-1]
res=[0 for _ in range(M+1)]
i=M//2
d=M//2
if K==0:
    print(M)
else:
    while True:
        d//=2
        res[i]=check(A,N,i,K)
        if i>0 and res[i-1]*res[i]==-1:
            ans=i
            break
        elif i<M and res[i]*res[i+1]==-1:
            ans=i+1
            break
        if res[i]==1:
            i-=d
        else:
            i+=d
    print(ans)
    print(res)

from math import ceil

def check(x):
    cnt = 0
    for a in A:
        cnt += ceil(a/x)-1
    return cnt <= K

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

left = 0
right = max(A)
while left < right-1:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)


Verdicts: Runtime Error

Accepted
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):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def check(1):
  count = 0
  for L in A:
    count = count + L // 1
    if L % 1 != 0:
      count = count + 1
    count = count - 1
  return count <= K

bottom, top = 0, max(A)

while top - bottom > 1:
  mid = (top + bottom) // 2
  if check(mid):
    top = mid
  else:
    bottom = mid

print(top)

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

def check(l):
    count = 0
    for L in A:
        count += L // l
        if L % l != 0:
            count += 1
        count -= 1
    return count <= K

bottom, top = 0, max(A)

while top - bottom > 1:
    mid = (top + bottom) // 2
    if check(mid):
        top = mid
    else:
        bottom = mid

print(top)


Verdicts: Runtime Error

Accepted
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 sys
import math
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()))
n,k = Mi()
a = Li()
sa = sum(a)
list.sort(a, reverse=True)
ma = sa//(n+k)+1
div = [0]*n
for i in range(n):
  div[i] = math.ceil(a[i]/ma)-1
  
sd = sum(div)
if sd > k:
  j = 0
  
      
list.sort(div, reverse=True)
print(div)
for i in range(n):
  a[i] = math.ceil(a[i]/(div[i]+1))
  
print(max(a))

import sys
import numpy as np
import math
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()))
n,k = Mi()
a = np.array(sys.stdin.readline().split(), np.int64)
maxa = np.max(a)
mina = maxa//(k+1)
while maxa > mina+1:
  mid = (mina+maxa)//2
  div = np.sum(np.ceil(a/mid-1))
  if div > k:
    mina = mid
  else:
    maxa = mid
  
print(maxa)

Verdicts: Wrong Answer

Accepted
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):
n,k=int(input())
A=list(map(int,input().split()))

right=10**9
left=1

while right-left>1 :
    mid=(left+right)//2
    count=0
    for a in A :
        count+=a//mid
        if a%mid==0 :
            count-=1
    if count<=k :
        right=mid
    else :
        left=mid

print(right)

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

right=10**9
left=0

while right-left>1 :
    mid=(left+right)//2
    count=0
    for a in A :
        count+=a//mid
        if a%mid==0 :
            count-=1
    if count<=k :
        right=mid
    else :
        left=mid

print(right)

Verdicts: Runtime Error

Accepted
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 math

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

def check(L):
    return sum(math.ceil(a / L)-1 for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if ok: 
        answer=min(m, answer)
        hi=m
    else:
        lo=m+1
print(answer))





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

def check(L):
    return sum(a // L for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if not ok: # 
        lo=m+1
    else:
        answer=min(m, answer)
        hi=m
print(answer))





import math

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

def check(L):
    return sum(math.ceil(a / L)-1 for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if ok: 
        answer=min(m, answer)
        hi=m
    else:
        lo=m+1
print(answer))





import math

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

def check(L):
    return sum(math.ceil(a / L)-1 for a in A) <= K

answer=max(A)
lo = 1
hi = answer+1
while lo < hi:
    m = (lo + hi)//2
    ok = check(m)
    if ok: 
        answer=min(m, answer)
        hi=m
    else:
        lo=m+1
print(answer)




Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
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 math
N,K = map(int,input().split())
a = list(map(int,input().split()))
def is_ok(arg):
    i = 0
    for item in a:
        i += a //arg -1
    return i <=K

def meguru_bisect(ng, ok):
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
    


import math
N,K = map(int,input().split())
a = list(map(int,input().split()))
low = 0
high = 10**9
while low  <= high:
    mid = (low+high)//2
    count = 0
    for item in a:
        count += math.ceil(a/mid)-1
    if count <= K:
        high = mid -1
    else:
        low = mid + 1
print(low)
    
    


import math
N,K = map(int,input().split())
a = list(map(int,input().split()))
def is_ok(arg):
    i = 0
    for item in a:
        i += math.ceil(item /arg) -1
    return i <=K

def meguru_bisect(ng, ok):
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(0,10**9))

Verdicts: Wrong Answer

Runtime Error

Accepted
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):
N, K = map(int, input().split())
A = list(map(int, input().split()))

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

left, right = 1, 10 ** 18
while right - left > 1:
    mid = (left + right) // 2
    if isOK(mid):
        left = mid
    else:
        right = mid
print(left)


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

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

left, right = 0, 10 ** 10
while right - left > 1:
    mid = (left + right) // 2
    if isOK(mid):
        right = mid
    else:
        left = mid
print(right)


Verdicts: Wrong Answer

Accepted
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):
def check(x, A, K):
    import math
    sumA = 0
    for a in A:
        if a > x:
            sumA += math.ceil(a / x) - 1
    if sumA <= K:
        return True
    else:
        return False


def resolve():
    import bisect
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ok = max(A)  # maxVal when minimize
    ng = 0  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid, A, K):
            ok = mid
        else:
            ng = mid
    print(ok)


def check(x, A, K):
    import math
    sumA = 0
    for a in A:
        if a > x:
            sumA += math.ceil(a / x) - 1
    if sumA <= K:
        return True
    else:
        return False


def resolve():
    import bisect
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ok = max(A)  # maxVal when minimize
    ng = 1  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid, A, K):
            ok = mid
        else:
            ng = mid
    print(ok)


def check(x, A, K):
    import math
    sumA = 0
    for a in A:
        if a > x:
            sumA += math.ceil(a / x) - 1
    if sumA <= K:
        return True
    else:
        return False


def resolve():
    _, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ok = max(A)  # maxVal when minimize
    ng = -1  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid > 0 and check(mid, A, K):
            ok = mid
        else:
            ng = mid
    print(ok)


resolve()


Verdicts: Wrong Answer

Wrong Answer

Accepted