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):
N,M,K=map(int,input().split())
import numpy as np
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))
a_s=a.cumsum()
b_s=b.cumsum()
an=0
ans=0
while an<N and a_s[an]<=K:
    bn=0
  while bn<M and a_s[an]+b_s[bn]<=K:
    bn+=1
  if an+bn+1>ans:
    ans=an+bn+1
  an+=1
print(ans)

N,M,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_s=[0]
b_s=[0]
for i in range(N):
  if a_s[i]+a[i]>K:
    break
  a_s.append(a[i]+a_s[i])
for i in range(M):
  if b_s[i]+b[i]>K:
    break
  b_s.append(b[i]+b_s[i])
bn=len(b_s)-1
ans=0
for i in range(len(a_s)):
  while a_s[i]+b_s[bn]>K:
    bn-=1
  ans=max(ans,i+bn)
  
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):
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

r0=0
rr = 0
t0=0
i = 0
j = 0
flag = 0

while t0<=K:
    t0 = t0 + A[i]
    if t0<=K:
        r0 = r0 + 1
        print(t0,r0)
        if i==N-1:
            break
        i = i + 1

if t0>K:
    t0 = t0 - A[i]

while t0<=K:
    t0 = t0 + B[j]
    if t0<=K:
        r0 = r0 + 1
        print(t0,r0)
        if j==M-1:
            flag = 1
            break
        j = j + 1

if t0>K:
    t0 = t0 - B[j]

rr = r0
Kk = K
tk = t0
rk = r0

for k in range(i):
    if flag == 1:
        break
    Kk = Kk + A[i-k] - tk
    print(Kk)
    tk = 0
    ik = 0
    rk = rk - 1
    while tk<=Kk:
        tk = tk + B[j]
        if tk<=Kk:
            rk = rk + 1
            print(tk,rk)
            if j == M-1:
                flag = 1
                break
            j = j+1
    rr = max(rk,rr)


print(rr)

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

def doku(li, K, time):
  cnt = 0
  tmp = 0
  for i in range(len(li)):
    if time+li[i] <= K:
      tmp += li[i]
      cnt += 1
    else:
      return cnt
  return cnt

ans = 0
time = 0
while time+min(A[0], B[0]) <= K:
  plus = min(A[0], B[0])
  time += plus
  ans += 1
  if A[0] <= B[0]:
    A.pop(0)
    if not A:
      ans += doku(B, K, time)
      print('A')
      break;
  else:
    B.pop(0)
    if not B:
      ans += doku(A, K, time)
      print('B')
      break;
  print(A, B, time, ans)
    
print(ans)

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])
  
ans = 0
j = 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 = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    print(B_check)
    while b - a != 0:
        c = int(round((a+b)/2))
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)

import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cum = [0]
B_cum = [0]
A_cum[0] = A[0]
for j in range(len(A)-1):
    A_cum.append(A_cum[j]+ A[j+1])
B_cum[0] = B[0]
for l in range(len(B)-1):
    B_cum.append(B_cum[l] + B[l+1])
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    b = bisect.bisect(B_cum,K-k)
    check = i+b+1
    if check>ans:
        ans = check
check = bisect.bisect(B_cum,K)
if check>ans:
    ans = check    
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):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

mmax = 0
pre = False
num = 0
ans = 0
ans2 = 0
for i in range(N+1):
  if i == 0:
    ans = 0
  else:
    ans += A[i-1]
  if ans > K:
    break
  for j in range(M+1):
    if j == 0:
      ans2 = ans
    else:
      ans2 += B[j-1]
    if ans2 > K:
      break
    else:
      mmax = max(mmax, i+j)
    print(i, j, ans2, mmax)

print(mmax)

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.appned(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

ans, j = 0, M
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)

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
pa, pb = 0, 0
 
ans = 0
fa, fb = False, False
while 1:
  if pa >= N and pb < M:
    if K - B[pb] >= 0:
      ans += 1
      pb += 1
    else:
      break
  elif pb >= M and pa < N:
    if K - A[pa] >= 0:
      ans += 1
      pa += 1
    else:
      break
  elif pa >= N and pb >= M:
    break
  elif A[pa] < B[pb]:
    if K - A[pa] >= 0:
      ans += 1
      pa += 1
    else:
      break
  else:
    if K - B[pb] >= 0:
      ans += 1
      pb += 1
    else:
      break
print(ans)

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

pa, pb = 0, 0

ans = 0
while 1:
  if A[pa] < B[pb]:
    if K - A[pa] >= 0:
      ans += 1
      pa += 1
    else:
      break
  else:
    if K - B[pb] >= 0:
      ans += 1
      pb += 1
    else:
      break

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

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

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

l = stdin.readline().rstrip().split(' ')
a = stdin.readline().rstrip().split(' ')
b = stdin.readline().rstrip().split(' ')
k = int(l[2])
n = int(l[0])
m = int(l[1])
ia = 0
ib = 0
b_sum = 0
count = 0
a_sum = 0
res = []

for ib in range(m):
    b_sum += int(b[ib])
    if b_sum <= k:
        count += 1
    else:
        break
res.append(count)
count = 0
for ia in range(n):
    a_sum = a_sum + int(a[ia])
    if k < a_sum:
        #print("ok")
        res.append(count)
        continue
    else:
        count = ia + 1
    b_sum = a_sum
    for ib in range(m):
        b_sum += int(b[ib])
        if b_sum <= k:
            count += 1
        else:
            break
    res.append(count)
print(res)

from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
a = stdin.readline().rstrip().split(' ')
b = stdin.readline().rstrip().split(' ')
k = int(l[2])
n = int(l[0])
m = int(l[1])
ia = 0
ib = 0
sum = 0
count = 0
a_sum = 0
res = []
b_list = []
for bt in b:
    sum += int(bt)
    if sum <= k:
        count += 1
        b_list.append(sum)
    else:
        break
#print(b_list)
res.append(count)
count = 0
ia = 1
for at in a:
    a_sum += int(at)
    if k < a_sum:
        print(max(res))
        sys.exit()
    count = ia
    sum = a_sum
    for bsum in b_list:
        sum = a_sum + bsum
        if k < sum:
            print(max(res))
            sys.exit()
        else:
            count += 1
    ia += 1
    res.append(count)
print(max(res))

from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = int(l[2])
n = int(l[0])
m = int(l[1])

sum = 0
a = [0]
for i in range(n):
    sum += A[i]
    a.append(sum)
sum = 0

b = [0]
for i in range(m):
    sum += B[i]
    b.append(sum)
#print(b)

ans = 0
j = 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

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

ans = 0

if ab_min > K:
    ans = 0
else:
    while True:
        K = K - min(A[0],B[0])
        if K < 0:
            break
        ans += 1
        if min(A[0],B[0])==A[0]:
            A.pop(0)
            if A == []:
                A.append(10**9+1)
        else:
            B.pop(0)
            if B == []:
                B.append(10**9+1)
print(ans)

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

ans = 0 
for i in range(n + 1):
    if a[i] > k:
        break
    while  a[i] + b[m] > k:
        m -= 1
    ans = max(ans, i + m)
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 bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_acc = [0]
b_acc = [0]
now = 0
for i in range(n):
  now += a[i]
  a_acc.append(now)

now = 0
for i in range(m):
  now += b[i]
  b_acc.append(now)

ans = 0
for i in range(n+1):
  t = k - a_acc[i]
  if t < 0:
    break
  ind = bisect.bisect_left(b_acc, t)
  ans = max(ans, i+ind)

print(ans)


import bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_acc = [0]
b_acc = [0]
now = 0
for i in range(n):
  now += a[i]
  a_acc.append(now)

now = 0
for i in range(m):
  now += b[i]
  b_acc.append(now)

ans = 0
for i in range(n+1):
  t = k - a_acc[i]
  if t < 0:
    break
  ind = bisect.bisect_left(b_acc, t)
  if ind == m+1:
    ans = max(ans, i+m)
    ind -= 1
  if b_acc[ind] == t:
    ans = max(ans, i+ind)
  else:
    ans = max(ans, i+ind-1)

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()))
time = 0
count = 0
Ain = 0
Bin = 0
lenA = len(A)
lenB = len(B)
if(min(min(A),min(B))>K):
    print(0)
    exit()
while time<=K:
    if((lenA!=Ain) and (lenB!=Bin)):
        if(A[Ain]<B[Bin]):
            time+= A[Ain]
            Ain+=1
            count +=1
        elif(A[Ain]>B[Bin]):
            time += B[Bin]
            Bin+=1
            count+=1
    if((lenA==Ain) and (lenB==Bin)):
        break
    elif(lenA==Ain):
        time += B[Bin]
        Bin += 1
        count += 1
    elif(lenB==Bin):
        time += A[Ain]
        Ain += 1
        count += 1
if(time == K):
    print(count)
else:
    print(count-1)

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
Ain = 0
Bin = 0
check = False
if(min(min(A),min(B))>K):
    print(0)
while K>=0:
    if(Ain != N and Bin !=M): 
        if(A[Ain] < B[Bin]):
            K-=A[0]
            Ain += 1
        else:
            K-=B[0]
            Bin += 1
        
    elif((Ain == N) and (Bin == M)):
        check = True
        break
    if(Ain==N):
        K -= B[Bin]
        Bin += 1
    elif(Bin==M):
        K -= A[Ain]
        Ain += 1
if(K==0 or check):
    print(Ain+Bin)
else:
    print(Ain+Bin-1)

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]
A_sum.extend(A)
B_sum.extend(B)
for i in range(1,N+1):
    A_sum[i]+=A_sum[i-1]
for i in range(1,M+1):
    B_sum[i]+=B_sum[i-1]
ans,j=0,M
for i in range(N+1):
    if A_sum[i]>K:
        break
    while B_sum[j]+A_sum[i]>K:
        j-=1
    ans = max(ans,i+j)
print(ans)

Verdicts: Wrong Answer

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 = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
import numpy as np
from itertools import accumulate
AS = np.array([0] + list(accumulate(A)))
BS = np.array([0] + list(accumulate(B)))

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


n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

from bisect import bisect
ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    
    # ans = max(ans, kb+i)
    ans = max(ans, bisect(BS, k - AS[i])-1+i)

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())) for _ in range(N)]

B = [list(map(int, input().split())) for _ in range(M)]

sum=0
count = 0
for i in range(N+M):
    if A[0] >= B[0]:
        temp = B.pop(0)
        if sum+temp > K:
            break
            print(count)
        else:
            sum +=temp
            count += 1

    else:
        temp = A.pop(0)
        if sum + temp > K:
            break
            print(count)
        else:
            sum += temp
            count += 1








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

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

B = list(map(int, input().split()))
sum=0
count = 0
for i in range(N+M):
    if A[0] >= B[0]:
        temp = B.pop(0)
        if sum+int(temp) > K:
            break
            print(count)
        else:
            sum +=temp
            count += 1

    else:
        temp = A.pop(0)
        if sum + int(temp) > K:
            break
            print(count)
        else:
            sum += temp
            count += 1








N,M,K = map(int, input().split())
  
A = [list(map(int, input().split())) for _ in range(N)]

B = [list(map(int, input().split())) for _ in range(M)]

sum=0
count = 0
for i in range(N+M):
    if A[0] >= B[0]:
        temp = B.pop(0)
        if sum+temp > K:
            break
            print(count)
        else:
            sum +=temp
            count += 1

    else:
        temp = A.pop(0)
        if sum + temp > K:
            break
            print(count)
        else:
            sum += temp
            count += 1








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])
# print(a)
# print(b)
# print(a[3])
ans=0
j = 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

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()))
ans = 0
while k > 0:
  i, j = 0
  if a[i] <= b[j]:
    k -= a[i]
    if k >= 0
      i += 1
      ans += 1
  else:
    k -= b[j]
    if k >= 0
      j += 1
      ans += 1
print(ans)

n ,m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while k > 0:
  i, j = 0
  if a[i] <= b[j]:
    k -= a[i]
    if k >= 0
      i += 1
      ans += 1
      if i >= n:
        for o in range(j, m):
          if k >= b[o]:
            k -= b[o]
            ans += 1
          else:
            k -= b[o]
            break
  else:
    k -= b[j]
    if k >= 0
      j += 1
      ans += 1
      if j >= m:
        for p in range(i, n):
          if k >= a[p]:
            k -= a[p]
            ans += 1
          else:
            k -= a[p]
            break
print(ans)

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

a_cs, b_cs = [0], [0]
for i in range(n):
  a_cs.append(a_cs[i] + a[i])
for i in range(m):
  b_cs.append(b_cs[i] + b[i])

ans, j = 0, m
for i in range(n+1):
  if a_cs[i] > k:
    break
  while b_cs[j] > k - a_cs[i]:
    j -= 1
  ans = min(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_cs, b_cs = [0], [0]
for i in range(n):
  a_cs.append(a_cs[i] + a[i])
for i in range(m):
  b_cs.append(b_cs[i] + b[i])

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

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())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

x = deque(a)
y = deque(b)

ans=0
for i in range(n + m):
    print(x, y)
    try:
        temp = x.popleft() if x[0] < y[0] else y.popleft()
    except:
        if len(x) == 0:
            temp = y.popleft()
        elif len(y) == 0:
            temp=x.popleft()
            print(temp)

    k -= int(temp)
    if k >= 0:
        ans += 1
    else:
        break
print(ans)

n,m,k = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

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

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):
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
A1 = [0]
for i, v in enumerate(A):
    x = A1[i]+v
    A1.append(x)
B = list(map(int, input().split()))
B1 = [0]
for i, v in enumerate(B):
    x = B1[i]+v
    B1.append(x)
c1 = 0
c2 = 0
ans = 0
temp = 0
print(A1, B1)
for i in range(len(A1)):
    if A1[i] > K:
        break
    for k in range(len(B1)):
        if B1[k] > K:
            break
        if A1[i]+B1[k] <= K:
            if i+k > ans:
                ans = i+k
print(ans)

from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
A1 = [0]
for i, v in enumerate(A):
    x = A1[i]+v
    A1.append(x)
B = list(map(int, input().split()))
B1 = [0]
for i, v in enumerate(B):
    x = B1[i]+v
    B1.append(x)
c1 = 0
c2 = 0
ans = 0
temp = M

for i in range(N+1):
    if A1[i] > K:
        break
    while B1[temp] > K-A1[i]:
        temp -= 1
    ans = max(ans, i+temp)
    # for k in range(temp, 0, -1):
    #     if A1[i]+B1[k] <= K:
    #         ans = max(ans, i+k)
    #         temp = k
    #         break
# print(c1, c2)

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=[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])
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]
b=[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):
N,M,K = input().split()

N = int(N)
M = int(M)
K = int(K)

A = list(input().split())
A = [int(c) for c in A]

Sum_A = [0]
ele_A = 0
a = 0

while Sum_A[-1] + A[a] <= K:
    ele_A += A[a]
    a += 1
    Sum_A.append(ele_A)
    if a == len(A):
        break

B = list(input().split())
B = [int(c) for c in B]

Sum_B = [0]
ele_B = 0
b = 0

while Sum_B[-1] + B[b] <= K:
    ele_B += B[b]
    b += 1
    Sum_B.append(ele_B)
    if b == len(B):
        break

h = len(Sum_A) - 1
i = 0
j = 0

while h > 0:
    while Sum_A[h] + Sum_B[i] <= K:
        j = max(j,h + i)
        i += 1
        if i == len(Sum_B) - 1:
            break
    if i == len(Sum_B) - 1:
        j = max(j,h + i)
        break
    h -= 1

print(j)

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

N = int(N)
M = int(M)
K = int(K)

A = list(input().split())
A = [int(c) for c in A]

Sum_A = [0]
ele_A = 0
a = 0

while Sum_A[-1] + A[a] <= K:
    ele_A += A[a]
    a += 1
    Sum_A.append(ele_A)
    if a == len(A):
        break

B = list(input().split())
B = [int(c) for c in B]

Sum_B = [0]
ele_B = 0
b = 0

while Sum_B[-1] + B[b] <= K:
    ele_B += B[b]
    b += 1
    Sum_B.append(ele_B)
    if b == len(B):
        break

h = len(Sum_A) - 1
i = 0
j = 0

while h >= 0:
    while Sum_A[h] + Sum_B[i] <= K:
        j = max(j,h + i)
        if i == len(Sum_B) - 1:
            break
        i += 1
    if h == 0:
        break
    h -= 1

print(j)

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):
#!/usr/bin/env python
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    if n < m:
        a_lst, b_lst = b_lst, a_lst
        n, m = m, n

    a_time = [0]
    b_time = []

    t = 0
    for a in a_lst:
        t += a
        if t > k:
            break
        a_time.append(t)
    t = 0
    for b in b_lst:
        t += b
        if t > k:
            break
        b_time.append(t)

    a_que = deque(a_time)
    b_que = deque(b_time)
    cnt = len(a_que)
    c_max = cnt - 1
    while c_max <= cnt and a_que and b_que:
        cnt -= 1
        a = a_que.pop()
        b = b_que.popleft()
        while a + b <= k:
            cnt += 1
            c_max = cnt
            if b_que:
                b = b_que.popleft()
            else:
                break

    print(c_max)


if __name__ == '__main__':
    main()


#!/usr/bin/env python
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    if n < m:
        a_lst, b_lst = b_lst, a_lst
        n, m = m, n

    a_time = [0]
    b_time = [0]

    t = 0
    for a in a_lst:
        t += a
        if t > k:
            break
        a_time.append(t)
    t = 0
    for b in b_lst:
        t += b
        if t > k:
            break
        b_time.append(t)

    ret = 0
    j = len(b_time) - 1
    for i, a in enumerate(a_time):
        while a + b_time[j] > k:
            j -= 1
        ret = max(ret, i+j)

    print(ret)

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

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = []
Bsum = []
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N):
    if Asum(t) > K:
        break
    if best < t+1:
        best=t+1
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+1+s+1:
                best=t+1+s+1
            Blast = s
            break
print(best)



import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = [0]
Bsum = [0]
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N+1):
    if Asum[t] > K:
        break
    if best < t+1:
        best=t+1
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+1+s+1:
                best=t+1+s+1
            Blast = s
            break
print(best)



import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = [0]
Bsum = [0]
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N+1):
    if Asum[t] > K:
        break
    if best < t:
        best=t
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+s+1:
                best=t+s+1
            Blast = s
            break
print(best)



import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = [0]
Bsum = [0]
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M
for t in range(N+1):
    if Asum[t] > K:
        break
    if best < t:
        best=t
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+s:
                best=t+s
            Blast = s
            break
print(best)



Verdicts: Runtime Error

Wrong Answer

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

from itertools import accumulate
a_acc=list(accumulate(a))
b_acc=list(accumulate(b))

cnt=0

import bisect
for i in range(n):
    nokori=k-a_acc[i]
    if nokori<b[0]:
        break
    b_i=bisect.bisect_right(b_acc,nokori)
    cnt=max(cnt,(i+1)+b_i)
    print(nokori,i,b_i)

print(cnt)


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

from itertools import accumulate
a_acc=list(accumulate(a))
b_acc=list(accumulate(b))
a_acc.insert(0,0)
b_acc.insert(0,0)

cnt=0

import bisect
for i in range(n+1):
    nokori=k-a_acc[i]
    if nokori<0:
        break
    b_i=bisect.bisect_right(b_acc,nokori)-1
    cnt=max(cnt,i+b_i)
    

print(cnt)

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()))
min = 0
cnt = 0
for i,k in enumerate(b):
    min += k
j = i
for i in range(N):
    while(j > 0 and min > K):
        j -= 1
        min -= b[j]
    if(min > K):
        break
    cnt = max(cnt, i + j)
    if(i == N):
        break
    min += a[i]
print(cnt)


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


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()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
idx = 0
ans = lim_a
for l in range(1, lim_a + 1):
  while True:
    if k >= cum_a[-l] + cum_b[idx]:
      ans = lim_a - l + idx + 2
    else:
      idx += 1
    idx += 1
print(ans)


n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
idx = 0
ans = lim_a
for l in range(1, lim_a + 1):
  for idx in range(lim_b):
    if k >= cum_a[-l] + cum[idx]:
      ans = max(ans, lim_a - l + idx + 2)
print(ans)


n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
idx = 0
ans = lim_a
for l in range(1, lim_a + 1):
  while idx < lim_b:
    if k >= cum_a[-l] + cum_b[idx]:
      ans = max(ans, lim_a - l + idx + 2)
    else:
      break
    idx += 1
ans = max(ans, lim_b)
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):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

p_time = 0
time = 0
while time < k:
    if len(a) > 0 and len(b) > 0:
        if a[0] >= b[0]:
            time += a[0]
            a.remove(a[0])
        else:
            time += b[0]
            b.remove(b[0])
    elif len(a) <= 0 and len(b) <= 0:
        break
    elif len(a) <= 0 < len(b):
        time += b[0]
        b.remove(b[0])
    elif len(b) <= 0 < len(a):
        time += a[0]
        a.remove(a[0])
    if time <= k:
        p_time += 1

print(p_time)


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

#include <algorithm>



int main()
{
    long long  n,m,k; std::cin >> n >> m >> k;
    // long long  a[n+1], b[m+1];
    std::vector<long long>  a{n+1}, b{m+1};
    a[0]=0; b[0]=0;
    for (int i=1;i<n+1;i++)
        std::cin >> a[i];
    for (int i=1; i<m+1; i++)
        std::cin >> b[i];
    
    for (int i=1; i<n+1; i++)
        a[i]+=a[i-1];
    for (int i=1; i<m+1; i++)
        b[i]+=b[i-1];

    int ans=0, r=m;
    for (int i=0; i<n+1; i++)
    {
        if(a[i]>k) break;
        while (a[i]+b[r]>k)
            r--;
        ans = std::max({ans, i+r});
    }
    
    std::cout << ans;

    return 0;
}

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

sa = [0]*(n+1)
sb = [0]*(m+1)

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

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

sa = [0]*(n+1)
sb = [0]*(m+1)

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

isb=m
ans = 0
for isa in range(n+1):
    if sa[isa]>k:
        break
    #while isb>0 and sa[isa]+sb[isb]>k:
    while sa[isa]+sb[isb]>k:
        isb-=1
    ans = max(ans, isa+isb)
    
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):
# -*- coding: utf-8 -*-

N, M, K = list(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[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)


# -*- coding: utf-8 -*-

def get_input() -> tuple:
    
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    return N, M, K, A, B


def main(N: int, M: int, K: int, A: list, B: list) -> None:
    
    
    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, 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)


if __name__ == "__main__":
    
    N, M, K, A, B = get_input()

    
    main(N, M, K, A, B)


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
pin = sys.stdin.readline
pout = sys.stdout.write
perr = sys.stderr.write

N, M, K = map(int, pin().split())
A = list(map(int, pin().split()))
B = list(map(int, pin().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])
ans = 0
print(a)
print(b)
for i in range(N + 1):
    
    if a[i] > K:
        break
    
    while b[M] > K - a[i]:
        M -= 1
    ans = max(ans, M + i)
print(ans)



import sys
pin = sys.stdin.readline
pout = sys.stdout.write
perr = sys.stderr.write

N, M, K = map(int, pin().split())
A = list(map(int, pin().split()))
B = list(map(int, pin().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])
ans = 0

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


Verdicts: Wrong Answer

Accepted