peterverebics/CodeNet_Python_118 huggingface dataset:
n, m, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
 
a_sum=[0]
for i in range(n):
  a_sum.append(a[i]+a_sum[i])
  
b_sum=[0]
for i in range(m):
  b_sum.append(b[i]+b_sum[i])
  
ans, j = 0, m
for i in range(n+1):
  if a_sum[i]>k:
    break
  while a_sum[i] + b_sum[j] > k and j>0:
    j-=1
  if a_sum[i]+b_sum[j]<=k:
    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)
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))
from itertools import accumulate

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

cost = 0
cnt = 0

a = [0] + list(accumulate(a))
b = [0] + list(accumulate(b))

ans = 0

b_cnt = m

for a_cnt in range(n+1):
    if a[a_cnt] > k:
        continue

    while b[b_cnt] > k - a[a_cnt]:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)
import bisect

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

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time >= 0:
        j = bisect.bisect(item2, remain_time) - 1
        ret = max(ret, i + j)

print(ret)
def solve():
    n,m,k = list(map(int,input().split()))
    arr = list(map(int, input().split()))
    arr1 = list(map(int, input().split()))
    aTrack = 0
    bTrack = sum(arr1)
    Bn = len(arr1)
    ans = 0
    for An in range(len(arr)+1):
      if An>0:
        aTrack += arr[An-1]
      if aTrack>k:
        break
      while aTrack+bTrack>k:
        Bn -= 1
        bTrack -= arr1[Bn]
      ans = max(ans, An+Bn)
    print(ans)
    
            
solve()
N, M, K = list(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[-1] + A[i])
for i in range(M):
    b.append(b[-1] + B[i])
    
ans, j = 0, 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)
n,m,k=map(int,input().split())
a=[0] + list(map(int,input().split()))
b=[0] + list(map(int,input().split()))

for i in range(1,n+1):
    a[i] += a[i-1]

for i in range(1,m+1):
    b[i] += b[i-1]

ans=0
j=m
for i in range(n+1):
    l = k - a[i]
    if(l<0):
        break
    while b[j]>l:
        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])
 
#print(a)
#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
    #print(i,j)
    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 = 0
j = m
for i in range(n+1):
    if A[i] > k:
        break
    else:
        while k - A[i] < B[j]:
            j -= 1

    ans = max(ans, i+j)

print(ans)
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans, tmp = 0, m
for i in range(n + 1):
    if SA[i] > k:
        break
    for j in range(tmp + 1)[::-1]:
        if SA[i] + SB[j] <= k:
            break
    ans = max(ans, i + j)
    tmp = j
print(ans)
import bisect
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum, bsum = [0], [0]
for i in range(n):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
for i in range(len(asum)):
  ans = max(ans, i + bisect.bisect(bsum, k-asum[i]) - 1)
print(ans)
import numpy as np
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
a.extend(np.cumsum(A, dtype="int64"))
b.extend(np.cumsum(B, dtype="int64"))

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

        j -= 1
    best = max(best, i + j)

print(best)
import bisect
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 = 0
for i in range(n+1):
  if a[i] > k:
    break
  ans = max(ans,i+bisect.bisect(b,k-a[i])-1)
print(ans)
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
b = list(map(int, input().split()))
A.insert(0, 0)
b.insert(0, 0)

A = list(accumulate(A))
b = list(accumulate(b))

ans = 0
for i, a in enumerate(A):
    if a > k:
        break
    index = bisect.bisect_right(b, k-a)
    ans = max(ans, i + index-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, j = 0, m
for i in range(n+1):
    if A[i] > k:
        break
    else:
        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()))

now = sum(b)
j = len(b)
while j > 0 and now > k:
    j -= 1
    now -= b[j]
ans = j
for i, ai in enumerate(a, 1):
    now += ai
    while j > 0 and now > k:
        j -= 1
        now -= b[j]
    if now > k:
        break
    ans = max(ans, i + j)
print(ans)
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(j) for j in 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()))

aL = [0 for _ in range(n+1)]
bL = [0 for _ in range(m+1)]

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

ans = 0
j = m

for i in range(n+1):
    if aL[i] > k:
        break
    while bL[j] > k - aL[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)
N, M , K = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
t = 0
R = 0
tmp = 0
for i in range(M):
    if tmp + Y[i] > K:
        break
    R += 1
    tmp += Y[i]

sY = sum(Y)
j = M
for i in range(N):
    t += X[i]
    if t > K:
        break
    while j:
        if sY + t <= K:
            break
        j-=1
        sY -= Y[j]
    R = max(R, j+i+1)
print(R)
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
j = m

#しゃくとり
for i in range(n+1):
    if sa[i] > k:
        break
    while sa[i]+sb[j] > k:
        j -= 1
    ans = max(ans, i+j)

print(ans)
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)
import bisect

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

A.insert ( 0 , 0 ) ;
B.insert ( 0 , 0 ) ;

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



t = 0 ;
for i , v in enumerate ( A ) :
	if v > K : break ;
	x2 = bisect.bisect_right( B , K - v ) ; 
	t = max ( t , x2 - 1 + i ) ;

print ( t ) ;
import bisect

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

timeA=[0]*(N+1)
timeB=[0]*(M+1)
for i in range(N):
    timeA[i+1]=timeA[i]+A[i]
for i in range(M):
    timeB[i+1]=timeB[i]+B[i]

ans=0
for i in range(N+1):
    time=K-timeA[i]
    if time<0:
        break
    num=bisect.bisect_right(timeB,time)
    ans=max(ans,i+num-1)
print(ans)
from itertools import accumulate

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

sa = [0] + list(accumulate(a))
sb = [0] + list(accumulate(b))

ans = 0
p = m
for i in range(n + 1):
    for j in range(p, -1, -1):
        if sa[i] + sb[j] <= k:
            ans = max(ans, i + j)
            p = j
            break
print(ans)
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))
from itertools import accumulate
N, M, K = map(int, input().split())
Nlist = [0]+list(map(int, input().split()))
Mlist = [0]+list(map(int, input().split()))
Asum = list(accumulate(Nlist))
Bsum = list(accumulate(Mlist))
count = 0
j = 0
for i in range(N, -1, -1):
    if K >= Asum[i]:
        while Asum[i]+Bsum[j] <= K:
            j += 1
            if j == M+1:
                break
        if count < i+j-1:
            count = i+j-1
    if j == M+1:
        break
print(count)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans1 = 0
for i in range(n-1):
    a[i+1] = a[i]+a[i+1]
for i in range(m-1):
    b[i+1] = b[i]+b[i+1]
import bisect
key = bisect.bisect(a,k)
for i in range(key):
    ans = 0
    ans += key-i
    time = a[key-i-1]
    ans += bisect.bisect(b,k-time)
    ans1 = max(ans1,ans)
ans = 0
ans += bisect.bisect(b,k)
ans1 = max(ans,ans1)

            
print(ans1)
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)
import numpy as np
N,M,K = map(int, input().split())

A = np.array([0] + list(map(int, input().split())))
B = np.array([0] + list(map(int, input().split())))

CA = np.cumsum(A)
CB = np.cumsum(B)

ans = 0
for i in range(N+1):
  if CA[i] > K:
    break
  j = np.searchsorted(CB, K-CA[i], side='right') - 1
  ans = max(ans, i+j)
  #print(ans,i,j)
  
#print(CA)
#print(CB)
print(ans)
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

A_sum = [0]
B_sum = [0]

for a in A_list:
    A_sum.append(A_sum[-1] + a)

for b in B_list:
    B_sum.append(B_sum[-1] + b)

count = 0
j = M
for i, a in enumerate(A_sum):
    if a > K:
        break
    while B_sum[j] > K - a:
        j -= 1
    if count < i + j:
        count = i + j

print(count)
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = tuple(accumulate([0] + AB[:N])), tuple(accumulate(AB[N:]))
    res = 0
    for i, a_time in enumerate(cum_A):
        if a_time > K:
            break
        b_time = K - a_time
        res = max(res, i + bisect(cum_B, b_time))
    print(res)


if __name__ == "__main__":
    main()
n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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=0

for i in range(n+1):
  # j=0
  if A[i]>k:
    break
  nokori=k-A[i]

  while(B[j]<=nokori and j<m):
    j+=1

  if nokori<B[j]:
    j-=1
    
  ans=max(ans,i+j)
print(ans)
from bisect import bisect_right
from itertools import accumulate

N, M, K, *AB = map(int, open(0).read().split())
A, B = AB[:N], AB[N:]

A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(A):
    if K - a < 0:
        break
    ans = max(ans, bisect_right(B, K - a) + i - 1)

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

print(answer)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cum_A=[0]
cum_B=[0]
for i in range(N):
  cum_A.append(cum_A[-1]+A[i])
for i in range(M):
  cum_B.append(cum_B[-1]+B[i])
ans, j = 0,M
for i in range(N+1):
  if cum_A[i] > K:
    break
  while cum_B[j] > K-cum_A[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)
from bisect import bisect_right
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 i in range(1, N+1):
    a[i] = a[i-1]+A[i-1]
for i in range(1, M+1):
    b[i] = b[i-1]+B[i-1]
ans = 0
for i in range(N+1):
    if a[i]>K:
        break
    j = bisect_right(b, K-a[i]) - 1
    ans = max(ans, i+j)
print(ans)
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def ruiseki(mydata):
    res = [0]*(len(mydata)+1)
    for i in range(len(mydata)):
        res[i+1] = res[i] + mydata[i]
    return res

n, k , m = MI()
a = ruiseki(LI())
b = ruiseki(LI())
a = a
b = b

result = 0
index = k
for i, ii in enumerate(a):
    if ii > m:
        break
    while b[index] + ii > m:
        index -= 1
    result = max(result, i+index)
print(result)
n, m, k = map(int, input().split())
A = [0] + list(map(int,input().split()))
B = [0] + list(map(int,input().split()))
 
for i in range(2,n+1):
    A[i] += A[i-1]
for i in range(2,m+1):
    B[i] += B[i-1]

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)
from itertools import accumulate
from bisect import bisect_right

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect_right(b, K - a[i])
    result = max(result, i + j - 1)
print(result)
import sys
import itertools as it
input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max, j = 0, M
for i in range(N+1):
    if AS[i] > K:
        break
    while i + j > max:
        if AS[i] + BS[j] <= K:
            max = i + j
            break
        j -= 1

print(max)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y=[0],[0]
for i in range(n):
    x.append(a[i]+x[i])
for j in range(m):
    y.append(b[j]+y[j])

ans=0
j=m
for i in range(n+1):
    if x[i]>k:
        break
    while y[j]>k-x[i]:
        j-=1
    ans=max(i+j,ans)
print(ans)
import bisect
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n+1):
  a[i] += a[i-1]
for j in range(1,m):
  b[j] += b[j-1]
ans = 0
for i in range(n+1):
  x = k-a[i]
  if x < 0:
    break
  ptr = bisect.bisect_right(b,x)
  ans = max(ans,ptr+i)
print(ans)
#!/usr/bin/env python3

import itertools
import bisect

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

cumA = list(itertools.accumulate(A))
cumB = list(itertools.accumulate(B))
#print(cumA)
#print(cumB)

ans = 0

for i in range(N+1):
    cnt = i
    chk = K - cumA[i]
    if chk < 0:
        continue
    cnt += bisect.bisect_right(cumB,chk)-1
    ans = max(ans,cnt)
    #print(ans)
print(ans)
from bisect import bisect_right
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A_sum = [0]*(N+1)
for i in range(N):
    A_sum[i+1] = A[i]+A_sum[i]
B_sum = [0]*(M+1)
for i in range(M):
    B_sum[i+1] = B[i]+B_sum[i]

ans = 0
for i in range(N+1):
    if 0 <= K-A_sum[i]:
        j = bisect_right(B_sum,K-A_sum[i])
        ans = max(ans,i+j-1)

print(ans)
import numpy as np
import sys
read = sys.stdin.read


N, M, K = map(int, input().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)

ans = 0
left = M
for i in range(len(A)):
    if A[i] > K:
        break

    while A[i] + B[left] > K:
        left -= 1

    ans = max(ans, left + i)

print(ans)
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,N):
  A[i] += A[i-1]
for i in range(1,M):
  B[i] += B[i-1]

  
ans = 0
for i in range(N):
  K1 = K - A[i]
  if(K1 >= 0):
    j = bisect.bisect_right(B, K1)
    ans = max(ans, i+j+1)
    
for i in range(M):
  K1 = K - B[i]
  if(K1 >= 0):
    j = bisect.bisect_right(A, K1)
    ans = max(ans, i+j+1)
print(ans)
import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]+list(accumulate(A))
b = [0]+list(accumulate(B))
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(' '))
ans = 0

a_ls = [0] + list(map(int, input().split(' ')))
b_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, n+1):
    a_ls[i] += a_ls[i-1]
for i in range(1, m+1):
    b_ls[i] += b_ls[i-1]

b_cnt = m
for a_cnt in range(0, n+1):
    if a_ls[a_cnt] > k:
        continue
    while a_ls[a_cnt] + b_ls[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_cs = [0] * (n + 1)
b_cs = [0] * (m + 1)

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

ans = 0
j = m
for i in range(n + 1):
    while j > 0 and a_cs[i] + b_cs[j] > k:
        j -= 1

    if a_cs[i] + b_cs[j] <= k:
        ans = max(ans, i + j)

print(ans)
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def ruiseki(mydata):
    res = [0]*(len(mydata)+1)
    for i in range(len(mydata)):
        res[i+1] = res[i] + mydata[i]
    return res

n, k , m = MI()
a = ruiseki(LI())
b = ruiseki(LI())

result = 0
index = k
for i, ii in enumerate(a):
    if ii > m:
        break
    while b[index] + ii > m:
        index -= 1
    result = max(result, i+index)
print(result)
from itertools import accumulate
from bisect import bisect_right

N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0
m = [0] + list(accumulate(A))
l = list(accumulate(B))
for i, x in enumerate(m):
    if x > K:
        break        
    else:
        ans = max(ans, i + bisect_right(l, K-x))
print(ans)
from bisect import bisect_right
from itertools import accumulate
def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cum_A = [0]+list(accumulate(A))
    cum_B = [0]+list(accumulate(B))

    ans = 0
    for i in range(N + 1):
        limit = K - cum_A[i]
        if limit < 0:
            break
        cnt = i
        cnt += bisect_right(cum_B, limit)-1
        ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    resolve()
def main():
    from itertools import chain

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

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


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

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

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

x = [0]

y = [0]

for i in range(n):
    x.append(x[i]+a[i])

for i in range(m):
    y.append(y[i]+b[i])

ans = 0

cnt = m

for i in range(n+1):
    
    if k-x[i]<0:
        break
    
    while y[cnt]>k-x[i]:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

AL = [0]
for i in range(N):
    AL.append(AL[-1] + A[i])
BL = [0]
for i in range(M):
    BL.append(BL[-1] + B[i])

ans = 0
from bisect import bisect_right
for i in range(N+1):
    zan = K - AL[i]
    if zan < 0:
        break
    ind = bisect_right(BL, zan) - 1
    ans = max(ans, i + ind)

print(ans)
n,m,p=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 i in range(n):
    a[i+1]+=a[i]+A[i]
for j in range(m):
    b[j+1]=b[j]+B[j]
    

now=-1
import bisect as bi
for i in range(n+1):
    if a[i]>p : break
    G=p-a[i]   
    now=max(bi.bisect(b, G)+i-1, now)

print(now)
N, M, K = map(int, input().split())
desk_a = list(map(int, input().split()))
desk_b = list(map(int, input().split()))

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

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

print(ans)
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
for i in range(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>=0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
print(ans)
import sys
input = sys.stdin.readline
import numpy as np

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

A = np.array([0] + list(map(int,input().split())))
B = np.array([0] + list(map(int,input().split())))

cA = np.cumsum(A)
cB = np.cumsum(B)
rcA = (K - cA)[::-1]
ind = N - np.searchsorted(rcA,cB,side='left')
cand = np.arange(M+1) + ind
cand *= (ind >= 0)
print(np.max(cand))