TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n=int(input())
c=list(input())
l,r=0,n-1
ans=0
while l<r:
    while c[l]!='W':
        l+=1
        if l>n-1:
            break
    while c[r]!='R' or r>=0:
        r-=1
        if r<0:
            break
    if l<r:
        ans+=1
        l+=1
        r-=1
print(ans)

n=int(input())
c=list(input())
l,r=0,n-1
ans=0
while l<r:
    while c[l]!='W':
        l+=1
        if l>n-1:
            break
    while c[r]!='R':
        r-=1
        if r<0:
            break
    if l<r:
        ans+=1
        l+=1
        r-=1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
    if n%2==0:
        tmpw=C.count("W")
        print(tmpw,C)
        C=C[tmpw:]
        print(tmpw,C)
        print(C.count("R"))
    else:
        tmpw=C.count("W")
        print(tmpw,C)
        C=C[tmpw-1:]
        print(tmpw,C)
        print(C.count("R"))
    
        

n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
        tmpw=C.count("W")
        #print(tmpw,C)
        #if tmpw%2==0:
        C=C[(n-tmpw):]
            #print(tmpw,C)
        print(C.count("R"))
        #else:
            #C=C[tmpw-1:]
            #print(tmpw,C)
            #print(C.count("R"))
        

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
C = input()
c_R = 0
c_W = 0
for c in C:
    if c == "R": c_R += 1
    else: c_W += 1
ans = min(c_R, c_W)


if C[0] + C[1] == "WR":
    C[2:].find("WR") != -1:
    C = list(C)
    C[0] = "R"
    C[C[2:].find("WR") + 1] = "W"
    C = "".join(C)
    
ind1 = C.find("RWR")
if ind1 != -1:
    ind2 = C[ind1 + 2:].find("WR")
else:
    ind2 = -1


while ((ind1 != -1) & (ind2 != -1)):
    C = list(C)
    C[ind1 + 1] = "R"
    C[ind2 + 1] = "W"
    C = "".join(C)

    ind1 = C.find("RWR")
    if ind1 != -1:
        ind2 = C[ind1 + 2:].find("WR")
    else:
        ind2 = -1


    


c_R = 0
c_W = 0
for c in C:
    if c == "R": c_R += 1
    else: c_W += 1
ans = min(ans,c_R, c_W)








    


n = int(input())
s = input()
a = 0
b = 0
for c in s:
    if c == "R": a += 1
ans = max(a,b)
for i in range(n):
    if s[i] == "R": a -= 1
    else: b += 1
    ans = min(ans, max(a, b))
print(ans)








    


Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
for i in range(len(c)/2):
    if c[i] == "R":
        cou += 1
print(cou)

n = int(input())
c = list(input())
c2 = c[::-1]
cou = 0
for i in range(len(c)//2):
    if c2[i] == "R":
        cou += 1
for i in range(len(c)//2):
    if c[i] == "W":
        if c[i+1] == "R":
            cou += 1
print(cou)

n = int(input())
c = list(input())
print(c[:c.count("R")].count("W"))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
import collections as c
n = int(input())
s = list(input())
cnt = 0

while c.Counter(s[:cnt+1])["W"]<c.Counter(s[cnt:])["R"]:
    cnt += 1
    
print(cnt)

n = int(input())
s = list(input())
cnt = 0
for i in s:
    if i == "R":
        cnt += 1
    else:
        break

a = s.count("R")-cnt
b = 0

while s[:b+1].count("W") < s[b:].count("R"):
    b += 1

print(min(a,b))

n = int(input())
s = input()
print(s.count("R")-s[:s.count("R")].count("R"))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
c = list(map(int, input().split()))
left = 0
cnt = 0
right = len(c) - 1
while left < n and right >=0 and left < right:
	while left < n and c[left] != 'W':
		left += 1
	while right >= 0 and c[right] != 'R':
		right -= 1
	if left< n and right >= 0 and left<right:
		c[left], c[right] = c[right], c[left]
		cnt += 1
		left += 1
		right -=1 
print(cnt)



n = int(input())
c = list(input())
left = 0
cnt = 0
right = len(c) - 1
while left < n and right >=0 and left < right:
    while left < n and c[left] != 'W':
        left += 1
    while right >= 0 and c[right] != 'R':
        right -= 1
    if left< n and right >= 0 and left<right:
        c[left], c[right] = c[right], c[left]
        cnt += 1
        left += 1
        right -=1 
print(cnt)



Verdicts: Runtime Error

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
C = list(input())
C_ = sorted(C)

wr = rw = 0
for i in range(len(C_)):
    if C[i] != C_[i]:
        if C[i] == 'R' and C_[i] == 'W':
            rw += 1
        else:
            wr += 1

print(max(wr, rw))


N = int(input())
C = list(input())
C_ = sorted(C)

wr = rw = 0
for i in range(len(C_)):
    if C[i] != C_[i]:
        if C[i] == 'R' and C_[i] == 'W':
            rw += 1
        else:
            wr += 1

print(max(wr, rw))


Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
n = int(input())
c = input()
na = len(c)
red = 0
whi = 0

cou_start = 0
cou = 0
for i in reversed(range(0,na)):
    if c[i] == "W":
        whi += 1
        if cou_start == 1:
            cou += 1
    else:
        red += 1
        
    #print(red,whi,cou)
    
    if red >= 2 and whi >= 1:
        cou_start=1
        

pri = min(whi,red)
if cou != 0:
	pri = min(cou,pri)
  
print(pri)

n = int(input())
c = list(input())

cour = c.count("R")
count = 0

for i in range(cour):
    if c[i] == "W":
        count += 1

print(count)

Verdicts: Wrong Answer

Accepted
Problem: An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white.  You can do the following two kinds of operations any number of times in any order:    * Choose two stones (not necessarily adjacent) and swap them.   * Choose one stone and change its color (from red to white and vice versa).  According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Submission attempts (in order):
#!/usr/bin/env python3
import time

k = int(input())
s = ''

rs = []

start = time.time()
cnt = 0 
while True:
    cnt += 1
    s += '7' 
    n = int(s)
    r = n%k 
    if r==0:
        print(cnt)
        exit()

    if r in rs: 
        print(-1)
        end = time.time()
        exit()

    rs.append(r)
    end = time.time()
    t = end-start 
    if t >= 1.8:
        print(k-1)
        exit()


#!/usr/bin/env python3

n = int(input())
given_s = input()
s = list(given_s)

nr = nw = 0 
nr = s.count('R')
nw = n-nr
ans = 0 

if nw == 0:
    print(ans)
    exit()

l = s[:nr]
ans = l.count('W')
print(ans)


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

x0, x1 = 0, 10**9
while x0 + 1  < x1:
  x = (x0+x1)//2
  suma=0
  for i in a:
    suma += (a//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)

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

x0, x1 = 0, 10**9
while x0 + 1  < x1:
  x = (x0+x1)//2
  suma=0
  for i in a:
    if i%x==0:
      suma+=(i//x)-1
    else:
      suma += (i//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)


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 math import ceil

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


def check(l):
    cnt = sum(ceil(a / l) - 1 for a in A)
    return cnt <= K

lb, ub = 0, max(A)
for _ in range(100):
    mid = (lb + ub) / 2
    if check(mid):
        ub = mid
    else:
        lb = mid
print(round(lb))

from math import ceil

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


def check(l):
    cnt = sum(ceil(a / l) - 1 for a in A)
    return cnt <= K

lb, ub = 0, max(A)
for _ in range(50):
    mid = (lb + ub) / 2
    if check(mid):
        ub = mid
    else:
        lb = mid
print(ceil(ub))

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, floor


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    lower = 1
    upper = 10 ** 9 + 7
    while upper - lower >= 1:
        target = (lower + upper) / 2
        now = 0
        for i in range(n):
            now += ceil(a[i] / target) - 1
        if now > k:
            lower = target
        else:
            upper = target
    print(floor(lower) if k > 0 else a[-1])


if __name__ == '__main__':
    main()



from math import ceil


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    ng = 0
    ok = a[-1]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        cnt = 0
        for i in range(n):
            cnt += (a[i] - 1) // mid
        if cnt <= k:
            ok = mid
        else:
            ng = mid
    print(ceil(ok) if k > 0 else a[-1])


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):
import math 
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=max((left+right)//2,1)

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

print(mid)

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

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

import math 
import bisect
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=N//2
while(right-left>=0):
    numofcut=0
    mid=(left+right)//2
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=A[i]//mid -1
        else:
            numofcut+=A[i]//mid
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid-1
    

print(mid)

import math 
import bisect
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A=sorted(A)
left=0
right=max(A)
mid=N//2
while(right-left>=1):
    numofcut=0
    mid=(left+right)//2
    for i in range(N):
        if A[i]%mid==0:
            numofcut+=A[i]//mid -1
        else:
            numofcut+=A[i]//mid
    #print(numofcut)
    if numofcut>K:
        left=mid+1
    else:
        right=mid
    

print(mid)

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

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

Verdicts: Runtime Error

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

import sys


def main():
    """Main program."""
    log_count, cut_count = (int(i) for i in sys.stdin.readline().split())
    logs = [int(i) for i in sys.stdin.readline().split()]
    high = max(logs)
    low = 1
    soln = high
    # Binary search for the answer.
    while low < high:
        mid = (low + high) // 2
        cuts_needed = 0
        if mid:
            cuts_needed = sum(log // mid for log in logs)
        if cuts_needed <= cut_count:
            soln = min(soln, mid)
            high = mid - 1
        else:
            low = mid + 1
    print(soln)


if __name__ == '__main__':
    main()



import sys
from math import ceil


def main():
    """Main program."""
    log_count, cut_count = (int(i) for i in sys.stdin.readline().split())
    logs = [int(i) for i in sys.stdin.readline().split()]
    high = max(logs)
    low = 1
    soln = high
    # Binary search for the answer.
    while low <= high:
        mid = (low + high) // 2
        cuts_needed = sum([int(ceil(log / mid)) - 1 for log in logs])
        if cuts_needed <= cut_count:
            soln = min(soln, mid)
            high = mid - 1
        else:
            low = mid + 1
    print(soln)


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):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
from heapq import heapify,heappop,heappush
def main():
    n, k, *a = map(int, read().split())
    minusa = [-ae for ae in a]

    heapify(minusa)
    while k > 0:
        maxa = heappop(minusa)
        heappush(minusa, maxa/2)
        k -= 1
        print(minusa)
    r = heappop(minusa)
    r *= -1
    r = ceil(r)
    print(r)

if __name__ == '__main__':
    main()


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

from math import ceil
def main():
    n, k = map(int, input().split())
    a = tuple(map(int, input().split()))

    def kaisu(long):
        return(sum([ceil(ae/long) - 1 for ae in a]))

    def bs_meguru(key):
        def isOK(index, key):
            if kaisu(index) <= key:
                return True
            else:
                return False
        ng = 0
        ok = max(a)
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if isOK(mid, key):
                ok = mid
            else:
                ng = mid
        return ok
    print(bs_meguru(k))

if __name__ == '__main__':
    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().strip().split()))

b = 0
e = max(A)
L = e // 2
while e - b >= 1:
    m = sum(list(map(lambda x: x // L, A)))
    if m <= k:
        e = L
        L = (e + b) // 2
    else:
        b = L
        L = (e + b) // 2
print(e)


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

b = 0
e = max(A)
L = e // 2
while e - b > 1:
    L = (e + b) // 2
    m = sum(list(map(lambda x: (x - 1) // L, A)))
    if m <= k:
        e = L
    else:
        b = L
print(e)


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):
#!/usr/bin/env python
# coding: utf-8

# In[16]:


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


# In[23]:


max(A)
cnt


# In[41]:


cnt = 0
low = 0
high = max(A)
ans = max(A)
old = int(high)
mycount = 0
while low < high:
    mid = (high+low)/2
    cnt = sum([(x-0.001)//mid for x in A])
    if cnt <= K:
        high = mid
        ans = min(ans, int(-(-mid//1)))
    else:
        low = mid
    if int(mid) == old:
        mycount += 1
    if mycount == 100:
        break
    old = int(mid)
print(ans)


# In[ ]:






#!/usr/bin/env python
# coding: utf-8

# In[16]:


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


# In[49]:


low = 0
high = max(A)
def ok(x):
    cnt = 0
    for a in A:
        cnt += (a//x)
        if a%x == 0:
            cnt -= 1
    return cnt <= K
 
while high-low > 1:
    mid = (high+low)//2
    if ok(mid):
        high = mid
    else:
        low = mid
print(high)


# In[ ]:






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()))
r = max(A)
l = 0
while l+1<r:
  mid=(l+r)//2
  if sum([a-1]//mid for a in A)>k:
    l=mid
  else:
    r = mid
print(r)


n,k=map(int,input().split())
A = list(map(int, input().split()))
r = max(A)
l = 0
while l+1<r:
  mid=(l+r)//2
  if sum([(a-1)//mid for a in A])>k:
    l=mid
  else:
    r = 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):
import numpy as np
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
cut = [1]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]

print(int(max(chip)))

import numpy as np
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
cut = [1]*N
chip = Logs
for i in range(K):
  x = np.argmax(Logs)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]
print(int(max(chip)))



import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))

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()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>1:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
print(mid)


n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>2:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
mid-=1
if mid<=0: mid=1
while True:
    temp=0
    flag=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: mid+=1
    else:
        flag=1
        break
    if flag: break
print(mid)

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):
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
a=[i*100 for i in a]
# Binary Search
def ok(x):
    c=0
    for i in a:
      c+=0--i//x
    return c<=n+k
l,r=0,10**11+1
while r-l>1:
  m=l+r>>1
  if ok(m): r=m
  else: l=m
print(l,r)
t=0--r//100
print(t-ok(t-1) if t>1 else t)

n,k,*a=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
  m=l+r>>1
  if sum(0--i//m for i in a)>n+k: l=m
  else: r=m
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):
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
floor = 1
ceil = max(a)
L = (ceil + floor)//2
 
 
def cut(long, logs):
    cnt = 0
    for i in logs:
        cnt += (i / long) - 1
        if i % long != 0:
            cnt += 1
    return cnt
 
 
while ceil - floor > 1:
    L = (ceil + floor)//2
    num = cut(L, a)
    if num > k:
        floor = L
    else:
        ceil = L
 
print(ceil)

import math

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

floor = 0
ceil = max(a)


def cut(long, logs):
    cnt = 0
    for i in logs:
        cnt += math.ceil(i / long) - 1
    return cnt


while ceil - floor > 1:
    L = (ceil + floor)//2
    num = cut(L, a)
    if num <= k:
        ceil = L
    else:
        floor = L

print(ceil)

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

low = 0
high = max(a)

while low + 1 < high:
    print(low, high)
    mid = (low + high) // 2
    m = 0
    for x in a:
        m += (x - 1) // mid
    
    if m <= k:
        high = mid
    else:
        low = mid

print(high)

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

low = 0
high = max(a)

while low + 1 < high:
    mid = (low + high) // 2
    m = 0
    for x in a:
        m += (x - 1) // mid
    
    if m <= k:
        high = mid
    else:
        low = mid

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

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

left=a[0]
right=a[n-1]
mid = (left+right)/2
while right - left > 1:
    times = 0
    for i in range(n):
        times+=math.ceil(a[i]/mid)-1
    if times<=k:
        right=mid
        mid=(left+right)/2
    else:
        left = mid
        mid =(left+right)/2

print(math.ceil(mid))


import math

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

left=0
right=max(a)
mid = (left+right)/2
while right - left > 0.5:
    times = 0
    for i in range(n):
        times+=math.ceil(a[i]/mid)-1
    if times<=k:
        right=mid
        mid=(left+right)/2
    else:
        left = mid
        mid =(left+right)/2

print(math.ceil(mid))


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())
a_list = list(map(int,input().split()))

min_num = 1
max_num = 10**9+1
while True:
    print(min_num)
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    #print(x)
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(min_num+1)
else:
    print(min_num)

import math
n,k = map(int,input().split())
a_list = list(map(int,input().split()))

min_num = 1
max_num = 10**9+1
while True:
    print(min_num)
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    #print(x)
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(int(min_num)+1)
else:
    print(int(min_num))

import math
n,k = map(int,input().split())
a_list = list(map(int,input().split()))

min_num = 1
max_num = 10**9+1
while True:
    #print(min_num)
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    #print(x)
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(min_num+1)
else:
    print(min_num)

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 numpy as np

N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])

L = np.max(A)

ans = L
low = 1
high = L
while 1:
    print(str(low) + ' ' + str(high))
    if low == high:
        ans = low
        break
    mid = (low + high) // 2
    if np.sum(A // mid) <= K:
        high = mid
    else:
        low = mid + 1

print(ans)

import numpy as np

N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])
I = np.array([1] * N)

L = np.max(A)

ans = L
low = 1
high = L
while 1:
    if low == high:
        ans = low
        break
    
    mid = (low + high) // 2
    if np.sum((A - I) // mid) <= K:
        high = mid
    else:
        low = mid + 1

print(ans)

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

m=1
M=10**9

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

def OK(k):
    if sum([ceil(a/k) for a in A])<=K:
        return True
    else:
        return False

while M-m>1:
    p=(m+M)//2
    if OK(p):
        m=p
    else:
        M=p
print(m)

from math import floor

m=0
M=10**9+1

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

def OK(p):
    if sum([(a-1)//p for a in A])<=K:
        return True
    else:
        return False

while M-m>1:
    p=(m+M)//2
    if OK(p):
        M=p
    else:
        m=p
print(M)

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

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    print(str(l)+":"+str(r))
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x

for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)

        
        

    


import math

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

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):

    
    x = (l+r)//2
    if x == 0:
        break

    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x
count = 0
ans = x
if(x!= 0 and l != 0):
        
    for i in range(N):
        count += math.ceil(a[i]/l)-1

    if (count <=K):
        ans = l
    else:
        ans = r

if l==0:
    ans = r
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):
from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
def chk(L):
    cnt = 0
    for i in range(N):
        cnt += ceil(A[i]/L)-1
    return cnt <= K
l, r = 1, max(A)
while l <= r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
print(max([x for x in [m-1,m,m+1] if x > 0 and chk(x)]))

from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
def chk(L):
    cnt = 0
    for i in range(N):
        cnt += ceil(A[i]/L)-1
    return cnt <= K
l, r = 1, max(A)
while l <= r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
print(max([x for x in [l-1, l, l+1, r-1,r,r+1, m-1,m,m+1] if chk(x)]))

from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
def chk(L):
    cnt = 0
    for i in range(N):
        cnt += ceil(A[i]/L)-1
    return cnt <= K
l, r = 1, max(A)
while l <= r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
print(max([x for x in [m-1,m,m+1] if chk(x)]))

from math import ceil
N, K = map(int,input().split())
A = list(map(int,input().split()))
def chk(L):
    cnt = 0
    for i in range(N):
        cnt += ceil(A[i]/L)-1
    return cnt <= K
l, r = 1, max(A)
while l <= r:
    m = (l+r)//2
    if chk(m):
        r = m-1
    else:
        l = m+1
print(min([x for x in [m-1,m,m+1] if x > 0 and chk(x)]))

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):
import numpy as np
from numba import jit
verbose = False

N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())), dtype=np.int64)

ul = np.ceil(np.sum(A)/(K))
ll= np.floor(np.max(A)/(K+1))

EPS = 1 / 10**6

@jit(nopython=True)
def cut(A, c, N):
    return (np.sum(np.ceil(A/c))-N)

c = np.ceil((ul+ll)/2)
mx = np.max(A)
while True:
    if ul-ll == 1:
        break
    nk = cut(A, c, N)
    if verbose:
        print('c:', c, 'nk:', nk, 'ul - ll:', ul, '/', ll)
    prev = c
    if nk  >K: # more cuts than target; larger logs can be made
        ll = c
        c = np.floor(ul + c)/2)
    else: #i.e. nk < K, less cuts than target
        ul = c
        c = np.ceil((c + ll)/2)
        
if cut(A, ll+EPS, N) >= K:
    print(np.min((np.max(A), int(ul))))
else:
    print(int(ll))
    


import numpy as np
from numba import jit
import random
verbose = False
rand = False

if rand:
    N, K = random.choice(range(10)), random.choice(range(10))
    A = np.array(random.choices(range(10**9), k=N))
else:
    N, K = list(map(int, input().split()))
    A = np.array(list(map(int, input().split())), dtype=np.int64)

ul = np.ceil(np.sum(A)/(K+1))
ll= np.floor(np.max(A)/(K+1))

EPS = 1 / 10**6

@jit(nopython=True)
def cut(A, c, N):
    return (np.sum(np.ceil(A/c))-N)

c = np.ceil((ul+ll)/2)
mx = np.max(A)
while True:
    if ul-ll <= 1:
        break
    nk = cut(A, c, N)
    if verbose:
        print('c:', c, 'nk:', nk, 'ul - ll:', ul, '/', ll)
    prev = c
    if nk  >K: # more cuts than target; larger logs can be made
        ll = c
        c = np.floor((ul + c)/2)
    else: #i.e. nk < K, less cuts than target
        ul = c
        c = np.ceil((c + ll)/2)
        
if cut(A, ll+EPS, N) >= K:
    print(np.min((np.max(A), int(ul))))
else:
    print(int(ll))
    


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, M = input().strip().split()
n, k = [int(N), int(M)]
a = list(map(int, input().strip().split()))
le = 0
ri = 10000000000
while ri - le > 1:
    mid = (le + ri) 
    num = 0
    for i in a:
        num += (i-1) 
    if num <= k:
        ri = mid
    else:
        le = mid
print(ri)


N, M = input().strip().split()
n, k = [int(N), int(M)]
a = list(map(int, input().strip().split()))
le = 0
ri = 10000000000
while ri - le > 1:
    mid = (le + ri)// 2
    num = 0
    for i in a:
        num += (i-1)// mid
    if num <= k:
        ri = mid
    else:
        le = mid
print(ri)


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

    


if __name__ == '__main__':
    main()

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n , k = map(int, input().split())
    a = list(map(int, input().split()))
    from heapq import heappop, heappush, heapreplace
    a = [-x for x in a]
    a.sort()
    for i in range(k):
        x = a[0]
        if abs(x) < 1:
            break
        heapreplace(a, x//3)
        heappush(a, x-x//2)
    ans = abs(a[0])
    print(ans)
    


if __name__ == '__main__':
    main()

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

    


if __name__ == '__main__':
    main()

Verdicts: 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):
import math

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)
    tA = []
    for a in A:
        tA.append((a, 1))

    for k in range(K):
        print('rope:' + str(k))
        a, diva = tA[1]
        b, divb = tA[0]
        print(tA)
        while b/divb > a/diva:
            divb += 1
        B = b/divb
        x = 1
        while x < N:
            xn, divx = tA[x]
            if xn/divx < B:
                break
            x += 1
        if x != N:
            tA.insert(x, (b, divb))
        else:
            tA.append((b, divb))
        tA = tA[1:]
        print(tA)
    print(math.ceil(tA[0][0]/tA[0][1]))


if __name__ == '__main__':
    main()



from math import ceil


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

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

    l = 0
    r = 1000000000

    while r-l > 1:
        mid = (l+r)//2
        if check(mid):
            r = mid
        else:
            l = mid
    print(r)
        


if __name__ == '__main__':
    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()))
ng = 0
ok = max(A)

def queri(n):
    count = 0
    for i in A:
        count += -(-i//n)
    if k>= count:
        return True
    else:
        return False

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

n,k = map(int,input().split())
A = list(map(int,input().split()))
ng = 0
ok = max(A)

def queri(n):
    count = 0
    for i in A:
        count += -(-i//n)-1
    if k>= count:
        return True
    else:
        return False

while ok - ng > 1:
    mid = (ok+ng)//2
    if queri(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):
mport math
def check(lis,k,mid):
	for i in lis:
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)/2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-0.000001
	else:
		a=mid+0.000001
print(int(math.ceil(ans)))

def check(lis,k,mid):
	for i in lis:
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=min(lis),max(lis)
ans=b
while(a<=b):
	mid=(a+b)//2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-1
	else:
		a=mid+1
print(ans)



def check(lis,k,mid):
	for i in lis:
		if(i%mid==0):
			k+=1
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)//2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-1
	else:
		a=mid+1
print(ans)


Verdicts: 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):
import sys


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

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

    return ans


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


if __name__ == '__main__':
    main()


import sys
from math import ceil, floor

def cut_logs(x, a):
    return sum(ceil(ai / x) - 1 for ai in a)


def resolve(in_):
    n, k = map(int, next(in_).split())
    logs = tuple(map(int, next(in_).split()))  # A
    assert n == len(logs)
    max_logs = max(logs)

    lb = 0
    ub = max_logs
    while ub - lb > 1:
        mid = (ub + lb) // 2
        v = cut_logs(mid, logs)
        # print(f'{lb=} {mid=} {ub=} {v<=k=} {v=} {k=}')
        if v <= k:
            ub = mid
        else:
            lb = mid
    # print(f'end: {lb=} {mid=} {ub=} {v<=k=} {v=} {k=}')

    return ub


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


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted