TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
from collections import deque
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = N + M
cnt = 0
res = 0
A = deque(A)
B = deque(B)
for c in range(C):
    if A:
        a = A.popleft()
    else:
        a = 10**10+1
    if B:
        b = B.popleft()
    else:
        b = 10**10+1
    if a >= b:
        cnt += b
        A.appendleft(a)
    elif a <= b:
        cnt += a
        B.appendleft(b)

    if cnt < K:
        res += 1
    else:
        break

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
while b[j] > K - a[i]:
    j -= 1
    ans = max(ans, i + j)
print(ans)

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[j] + b[j])
    
ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b_sum[i] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

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

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[j] + b[j])
    
ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b_sum[i] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

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

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[j] + b[j])
    
ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[i] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

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

a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i] + a[i])
for i in range(m):
    b_sum.append(b_sum[i] + b[i])
    
ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
n,m,k = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
b = sum(B)
ka = k
i = m
re = 0
for a in A:
  if ka < 0:
    break
  while ka < b and i > 0:
    b -= B[i]
    i -= 1
  ka -= a
  re += 1
  
print(re+i)

n,m,k = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
b = sum(B)
ka = k
i = m
c = 0
re = 0
A.insert(0, 0)
for a in A:
  ka -= a
  if ka < 0:
    break
  while ka < b and i > 0:
    i -= 1
    b -= B[i]
  c += 1
  re = max(re, c+i)

  
print(re-1)  

Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
import sys
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=A+B
d=0
C.sort()
if sum(C)<=K :
    print(len(C))
    sys.exit()
for i in range(len(C)) :
    d=d+C[i]
    if d>K :
        print(i+1)
        sys.exit()

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

a=[0]
b=[0]

for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
j=M
ans=0
for i in range(N+1):
    if a[i]>K:    
        break
    while b[j]>K-a[i] : 
        j-=1            
    ans=max(ans,i+j)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
c = 0
while K > 0:
    if not A == [] and not B == []:
        if A[0] >= B[0]:
            K = K - A[0]
            A.remove(A[0])
            if K >= 0:
                c += 1
        else:
            K = K - B[0]
            B.remove(B[0])
            if K >= 0:
                c += 1
    if A == []:
        K = K - B[0]
        B.remove(B[0])
        if K >= 0:
                c += 1
    if B == []:
        K = K - A[0]
        A.remove(A[0])
        if K >= 0:
                c += 1
print(c)

N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
c = 0
while K > 0:
    if not A == [] and not B == []:
        if A[0] >= B[0]:
            K = K - A[0]
            A.remove(A[0])
            if K >= 0:
                c += 1
        else:
            K = K - B[0]
            B.remove(B[0])
            if K >= 0:
                c += 1
    if A == []:
        K = K - B[0]
        B.remove(B[0])
        if K >= 0:
            c += 1
    if B == []:
        K = K - A[0]
        A.remove(A[0])
        if K >= 0:
            c += 1
print(c)

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])

ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j = j -1
    ans = max(ans, i+j)
    
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))


l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)

import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))

ans = 0
l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
def resolve():
    import numpy as np

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

    A_cumsum = np.cumsum(A)
    B_cumsum = np.cumsum(B)

    ans = 0
    j = M
    for i in range(N + 1):
        if A_cumsum[i] > K:
            break
        while A_cumsum[i] + B_cumsum[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)

resolve()

def resolve():
    import numpy as np

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

    A = np.insert(np.cumsum(A), 0, 0)
    B = np.insert(np.cumsum(B), 0, 0)

    ans = 0
    j = M
    for i in range(N + 1):
        if A[i] > K:
            break
        while A[i] + B[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)

resolve()


Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

TA = 0
T = [0]
cnt = [] # idx = n of B books

for i in range(len(A)):
  TA += A[i]
  if TA <= K:
    T.append(TA)
  else:
    break

cnt.append(len(T) - 1)

for j in range(len(B)):
  print(T)
  print(cnt)
  T = list(filter(lambda t: t<= K, list(map(lambda t: t + B[j], T))))
  cnt.append(len(T) - 1)
  if len(T) <= 0:
    break

for k in range(len(cnt)):
  cnt[k] += k

print(max(cnt))

def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

ta = 0
tb = 0
TA = [0]
TB = [0]

for i in range(len(A)):
  ta += A[i]
  if ta <= K:
    TA.append(ta)
  else:
    break
for j in range(len(B)):
  tb += B[j]
  if tb <= K:
    TB.append(tb)
  else:
    break

Cij = [0]

j = len(TB) - 1
for i in range(len(TA)):
  while TA[i] + TB[j] > K:
    j += -1
  else:
    if j >= 0:
      Cij.append(i + j)
  if j == -1:
    break


print(max(Cij))


Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
n,m,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))


sa = [0]*len(a)
sa[0] = a[0]
for i,k in enumerate(a):
    if i == 0:continue
    sa[i] = sa[i-1] + a[i]
sb = [0]*len(b)
sb[0] = b[0]
for i,k in enumerate(b):
    if i == 0:continue
    sb[i] = sb[i-1] + b[i]

ai = len(a)-1
bi = len(b)-1

minu = sa[ai] + sb[bi]
while(minu > K):
    if (sa[ai] - sa[ai-1]) > (sb[bi] - sb[bi-1]):
        ai -= 1
        minu = sa[ai] + sb[bi]
    else:
        bi -= 1
        minu = sa[ai] + sb[bi]

print(sa)
print(sb)
print(ai + bi + 2)


n,m,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))


sa = [0]*len(a)
sa[0] = a[0]
for i,k in enumerate(a):
    if i == 0:continue
    sa[i] = sa[i-1] + a[i]
sb = [0]*len(b)
sb[0] = b[0]
for i,k in enumerate(b):
    if i == 0:continue
    sb[i] = sb[i-1] + b[i]

ai = len(a)-1
bi = len(b)-1

minu = sa[ai] + sb[bi]
while(minu > K):
    if (sa[ai] - sa[ai-1]) > (sb[bi] - sb[bi-1]):
        ai -= 1
        minu = sa[ai] + sb[bi]
    else:
        bi -= 1
        minu = sa[ai] + sb[bi]

print(ai + bi + 2)


n,m,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))


sa = [0]
sb = [0]
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])
    

ans = 0
for i in range(n+1):
    if a[i] > k:
        break
    while b[m] > k - a[i]:
        m -= 1
    ans = max(ans,i+m)
print(ans)

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


sa = [0]
sb = [0]
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])


ans = 0
for i in range(n+1):
    if sa[i] > k:
        break
    while sb[m] > k - sa[i]:
        m -= 1
    ans = max(ans,i+m)
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):

def main():
    n, m, k = list(map(int, input().split()))
    a_books = list(map(int, input().split()))
    b_books = list(map(int, input().split()))
    a_idx = -1
    b_idx = -1
    sumbooks = sum(a_books) + sum(b_books)
    count = len(a_books) + len(b_books)
    if a_books[0] > k and b_books[0] > k:
        print(0)
        exit()
    elif sumbooks <= k:
        print(len(a_books) + len(b_books))
        exit()

    while sumbooks > k:
        # print(sumbooks, a_idx, b_idx)

        if b_idx >= len(b_books)*-1 and a_idx >= len(a_books)*-1:
            break
        elif b_idx >= len(b_books)*-1 or (a_idx < len(a_books)*-1 and a_books[a_idx] < b_books[b_idx]):
            sumbooks += a_books[a_idx]
            a_idx += -1
        elif a_idx >= len(a_books)*-1 or (b_idx < len(b_books)*-1 and b_books[b_idx] < a_books[a_idx]):
            sumbooks += b_books[b_idx]
            b_idx += -1
        if sumbooks <= k:
            break
        count += 1
    print(count)


if __name__ == '__main__':
    main()


def main2():
    n, m, k = list(map(int, input().split()))
    a_books = list(map(int, input().split()))
    b_books = list(map(int, input().split()))

    a, b = [0], [0]
    
    for i in range(len(a_books)):
        a.append(a[i] + a_books[i])

    for i in range(len(b_books)):
        b.append(b[i] + b_books[i])
    ans, j  = 0, len(b_books)
    
    for i in range(len(a)):
        if a[i] > k :
            break
        while b[j] > k - a[i]:
            j -= 1
        ans = max(ans, i+j)
    print(ans)


if __name__ == '__main__':
    main2()



Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
a,b = [0],[0]
for i in range(N):
    a.append(a[i]+A[i]
for i in range(M):
    b.append(b[i]+B[i])
 
ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break    
    while b[j]>K-a[i]:
        j -= 1    
   ans = max(ans,i+j)
print(ans)

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
a,b = [0],[0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
 
ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break    
    while b[j]>K-a[i]:
        j -= 1    
    ans = max(ans,i+j)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
import numpy as np

N,M,K = map(int,input().split())
A = np.array(input().split(),dtype=int)
B = np.array(input().split(),dtype=int)

AA = np.insert(A,0,0)
BB = np.insert(B,0,0)
AAA = np.cumsum(AA)
BBB = np.cumsum(BB)
max_mins = 0
max_books = 0
for a in enumerate(AAA):
    if a[1] > K:
        break
    for b in enumerate(BBB):
        if a[2] + b[1] > K:
            break
        if a[0] + b[0] > max_books:
            max_books = a[0] + b[0]
print(max_books)            


import numpy as np
from bisect import bisect

N,M,K = map(int,input().split())
A = np.array(input().split(),dtype=int)
B = np.array(input().split(),dtype=int)

AA = np.insert(A,0,0)
BB = np.insert(B,0,0)
AAA = np.cumsum(AA)
BBB = np.cumsum(BB)
max_books = 0
for a in enumerate(AAA):
    if a[1] > K:
        break
    books = a[0]
    ind = bisect(BBB,K - a[1])
    books += (ind-1)
    max_books = max(books,max_books)
print(max_books)        
    
    


Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
import numpy as np
n, m, k = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = [a for a in np.cumsum([0] + A) if a <= k]
B = [b for b in np.cumsum([0] + B) if b <= k]
B, A = sorted((A, B), key=len)
for i, a in enumerate(A[::-1]):
    for j, b in enumerate(B[::-1]):
        if a + b <= k:
            n_read = len(A) + len(B) - i  - j - 2
            break
    if a + b <= k:
        break
print(n_read)

@profile
def main():
    from numpy import cumsum
    n, m, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A = cumsum([0] + A)
    B = cumsum([0] + B)
    n_read = 0
    b_tail = B[-1]
    for i, a in enumerate(A):
        if a > k:
            break
        j = m
        if b_tail + a > k:
            for j, b in enumerate(B):
                if a + b > k:
                    break
        n_read = max(n_read, i + j)
    print(n_read)
main()


from numpy import cumsum
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A = cumsum([0] + A)
B = cumsum([0] + B)
n_read = 0
b_tail = B[-1]
for i, a in enumerate(A):
    if a > k:
        break
    j = m
    if b_tail + a > k:
        for j, b in enumerate(B):
            if a + b > k:
                break
    n_read = max(n_read, i + j)
print(n_read)


from numpy import cumsum
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A = cumsum([0] + A)
B = cumsum([0] + B)
n_read = 0
l = len(B) - 1
for i, a in enumerate(A):
    if a > k:
        break
    for j, b in enumerate(B[l::-1]):
        if a + b <= k:
            l -= j
            n_read = max(n_read, i + l)
            break
print(n_read)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M, K = NMI()
    A = NLI()
    B = NLI()
    
    cumsum_A = [0 for _ in range(len(A)+1)]
    cumsum_B = [0 for _ in range(len(B)+1)]    
    
    cnt = 0
    
    for n in range(N):
        cnt += A[n]
        cumsum_A[n+1] = cnt
        
    cnt = 0
    
    for m in range(M):
        cnt += B[m]
        cumsum_B[m+1] = cnt
    

    
    ans = 0
    
    for n in range(N+1):
        remain_K = K - cumsum_A[n]
        if remain_K < 0:
            break
        else:
            for m in range(M,-1,-1):
                if cumsum_B[m]> remain_K:
                    continue
                else:
                    print(ans,n,m)
                    ans = max(ans,n+m)
                break
    
    print(ans)
            
    


if __name__ == '__main__':
    main()

import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M, K = NMI()
    A = NLI()
    B = NLI()
    
    cumsum_A = [0 for _ in range(len(A)+1)]
    cumsum_B = [0 for _ in range(len(B)+1)]    
    
    cnt = 0
    
    for n in range(N):
        cnt += A[n]
        cumsum_A[n+1] = cnt
        
    cnt = 0
    
    for m in range(M):
        cnt += B[m]
        cumsum_B[m+1] = cnt
    

    
    ans = 0
    b= M
    
    for n in range(N+1):
        remain_K = K - cumsum_A[n]
        if remain_K < 0:
            break
        else:
            for m in range(b,-1,-1):
                if cumsum_B[m]> remain_K:
                    continue
                else:
                    b = m
                    ans = max(ans,n+m)
                break
    
    print(ans)
            
    


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**1000000000)

# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N, M, K = map(int, input().split())

    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    def dfs(n, m, total, count):
        if total > K:
            return count - 1

        if n == N and m == M:
            return count

        if n < N:
            c1 = dfs(n+1, m, total+As[n], count+1)
        else:
            c1 = count

        if m < M:
            c2 = dfs(n, m+1, total+Bs[m], count+1)
        else:
            c2 = count

        return max(c1, c2)

    return dfs(0, 0, 0, 0)


def main():
    print(solve())


if __name__ == "__main__":
    main()


from itertools import chain


def solve():
    N, M, K = map(int, input().split())

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

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain and idx_b >= 0:
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        i += idx_b
        answer = i if answer < i else answer

    return answer


def main():
    print(solve)


if __name__ == "__main__":
    main()


from itertools import chain


def solve():
    N, M, K = map(int, input().split())

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

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain and idx_b >= 0:
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        i += idx_b
        answer = i if answer < i else answer

    return answer


def main():
    print(solve())


if __name__ == "__main__":
    main()


Verdicts: Time Limit Exceeded

Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
#C
from itertools import accumulate
import bisect

n,m,k = map(int,input().split())
a = deque(map(int,input().split()))
b = deque(map(int,input().split()))

cnt = 0

a_c = list(accumulate(list(a)))
b_c = list(accumulate(list(b)))
result = []

idx_a = bisect.bisect_left(a_c,k)
idx_a_b = bisect.bisect_left(b_c,k-list(a)[idx_a])
result.append(idx_a + idx_a_b)

idx_b = bisect.bisect_left(b_c,k)
idx_b_a = bisect.bisect_left(a_c,k-list(b)[idx_b])
result.append(idx_b + idx_b_a)

for i in range(n+m):
    if len(a) > 0 and len(b) > 0:
        s,t = a.popleft(),b.popleft()
    elif len(a) > 0:
        s = a.popleft()
        t = float('inf')
    elif len(b) > 0:
        s = float('inf')
        t = b.popleft()
    else:
        break
    if s >= t:
        k -= t
        a.appendleft(s)
    else:
        k -= s
        b.appendleft(t)
    if k < 0:
        break
    else:
        cnt += 1
        #print('a:',a)
        #print('b:',b)
    
result.append(cnt)

print(min(result))

#C
from itertools import accumulate
from collections import deque
import bisect

n,m,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0] + list(map(int,input().split()))

cnt = 0

a_c = list(accumulate(list(a)))
b_c = list(accumulate(list(b)))
result = []

for i in range(n+1):
    if a_c[i] > k:
        continue
    b_idx = bisect.bisect_left(b_c,k-a_c[i]+1)
    result.append(i+b_idx-1)
    
print(max(result))


Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]

for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
	break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

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

a, b = [0], [0]
 
for i in range(N):
	a.append(a[i] + A[i])
    
for i in range(M):
	b.append(b[i] + B[i])
    
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    

    if A[-1]+B[-1]<=k:
        ans=n+m

    b_s=m

    for i in range(n+1):

        if A[i]>k:
            #print(i)
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(b_s,-1,-1):
            #print(i,i2)
            #print(A[i]+B[i2])
            if A[i]+B[i2]<k:
                temp=i+i2-1
                b_s=i2
                #print(ans,temp)
                ans=max(ans,temp)
                break
        

    
    print(ans)

if __name__ == '__main__':
    do()

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    

    if A[-1]+B[-1]<=k:
        ans=n+m

    b_s=m

    for i in range(n+1):

        if A[i]>k:
            #print(i)
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(b_s,-1,-1):
            #print(i,i2)
            #print(A[i]+B[i2])
            if A[i]+B[i2]<=k:
                temp=i+i2
                b_s=i2
                #print(ans,temp)
                ans=max(ans,temp)
                break
        

    
    print(ans)

if __name__ == '__main__':
    do()

Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range)m:
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if a[i] > k:
        break;
    while b[m] > k-a[i]:
        m -= 1
    e = max(e, i+m)
print(e)

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range(m):
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if a[i] > k:
        break;
    while b[m] > k-a[i]:
        m -= 1
    e = max(e, i+m)
print(e)

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range(m):
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if c[i] > k:
        break;
    while c[i]+d[m] > k:
        m -= 1
    e = max(e, i+m)
print(e)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
now_a = 0
now_b = 0
while k > 0 and a[now_a] < k or b[now_b] < k:
  if a[0] > b[0] and now_a > len(a) or now_b < len(b):
    k -= b[now_b]
    now_b += 1
  else:
    k -= a[now_a]
    now_a += 1
  count += 1
  
print (count)

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
_sum = 0

for i in range(n):
  a.append(a[i] + A[i])
for i in range(m):
  b.append(b[i] + B[i])
  
j = m
counts = [0]
for i in range(n + 1):
  if (a[i] > k):
    break
  while b[j] > k - a[i]:
    j -= 1
  counts.append(i + j)
  
print (max(counts))

Verdicts: Runtime Error

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
N,M,K = map(int,input().split(" "))

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

time_A = [0]*(N+1)
time_B = [0]*(M+1)

for i in range(N):
    time_A[i+1] = time_A[i] + A[i]
print(time_A)
for j in range(M):
    time_B[j+1] = time_B[j] + B[j]

ans = 0
l = M

for k in range(N+1):
    if time_A[k] > K:
        break
    while time_A[k] + time_B[l] > K:
        l -= 1
    ans = max(ans,k+l)

print(ans)

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

time_A = [0]*(N+1)
time_B = [0]*(M+1)

for i in range(N):
    time_A[i+1] = time_A[i] + A[i]
for j in range(M):
    time_B[j+1] = time_B[j] + B[j]

ans = 0
l = M

for k in range(N+1):
    if time_A[k] > K:
        break
    while time_A[k] + time_B[l] > K:
        l -= 1
    ans = max(ans,k+l)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
ans = max(ans, i + j)
print(ans)

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

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
from bisect import bisect
from collections import deque

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

for i in range(1, len(A)+1):
    A[i] += A[i-1]
for i in range(1, len(B)+1):
    B[i] += B[i-1]

indexB = len(B) - 1
results = [0]
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    enable_for_b = K - time
    results.append(i + bisect(B, enable_for_b))

print(max(results))

from collections import deque

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

for i in range(1, len(A)):
    A[i] += A[i-1]
for i in range(1, len(B)):
    B[i] += B[i-1]

indexB = len(B)
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    while(indexB >= 0 and time + B[indexB] > K):
        indexB -= 1
    count = i+1 + indexB+1
    if (best < count):
        best = count
print(best)

from bisect import bisect
from collections import deque

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

A = [0]
for i in range(1, len(A)):
    A[i] += A[i-1]
for i in range(1, len(B)):
    B[i] += B[i-1]

indexB = len(B) - 1
results = [0]
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    enable_for_b = K - time
    results.append(i + bisect(B, enable_for_b))

print(max(results))

from bisect import bisect
from collections import deque

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

for i in range(1, len(A)):
    A[i] += A[i-1]
for i in range(1, len(B)):
    B[i] += B[i-1]
A.insert(0, 0)
indexB = len(B) - 1
results = [0]
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    enable_for_b = K - time
    results.append(i + bisect(B, enable_for_b))

print(max(results))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.  It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).  Consider the following action:    * Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.  How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Submission attempts (in order):
from collections import deque

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

bookA = deque(list(map(int, input().split())), N)
bookB = deque(list(map(int, input().split())), M)

cnt = 0
while K >= 0:
    if len(bookA) == 0 and len(bookB) == 0:
        break
    elif len(bookA) > 0 and len(bookB) == 0:
        K -= bookA.popleft()
    elif len(bookA) == 0 and len(bookB) > 0:
        K -= bookB.popleft()
    elif len(bookA) > 0 and len(bookB) > 0:
        if bookA[0] >= bookB[0]:
            K -= bookA.popleft()
        else:
            K -= bookB.popleft()
    if K >= 0:
        cnt += 1

print(cnt)

from collections import deque
import random


"""
def mine(k, a, b):
    bookA = deque(a)
    bookB = deque(b)

    cnt = 0
    r = k
    while r > 0:
        if len(bookA) == 0 and len(bookB) == 0:
            break
        elif len(bookA) > 0 and len(bookB) == 0:
            r -= bookA.popleft()
        elif len(bookA) == 0 and len(bookB) > 0:
            r -= bookB.popleft()
        elif len(bookA) > 0 and len(bookB) > 0:
            if bookA[0] <= bookB[0]:
                r -= bookA.popleft()
            else:
                r -= bookB.popleft()
        if r >= 0:
            cnt += 1
    return cnt
"""



def tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    da = [0]
    db = [0]
    for i in range(n):
        da.append(da[i] + a[i])
    for i in range(m):
        db.append(db[i] + b[i])

    cnt = 0
    j = m
    for i in range(n+1):
        if da[i] > k:
            break
        while db[j] > k - da[i]:
            j -= 1
        cnt = max(cnt, i+j)

    return print(cnt)


tsundoku()
"""
for t in range(100):
    n = random.randint(1, 200000)
    m = random.randint(1, 200000)
    k = random.randint(1, 1000000000)
    a = [random.randint(1, 1000000000) for i in range(n)]
    b = [random.randint(1, 1000000000) for i in range(m)]

    res1 = mine(k, a, b)
    res2 = answer(n, m, k, a, b)
    if res1 != res2:
        print(res1, end=' ')
        print(res2, end=' \t')
        print(a[0:3], b[0:3])
        print(k)
"""

Verdicts: Wrong Answer

Accepted