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

import numpy as np
A = [0] + A
B = [0] + B
AA = np.cumsum(A)
BB = np.cumsum(B)

ans = 0
jmax = M
for i in range(1, N+1):
    a = AA[i]
    for j in range(jmax, 0, -1):
        b = BB[j]
        if a + b <= K:
            ans = max(ans, i+j)
            break
    jmax = j
print(ans)
def hoge():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A = [10**10]+A[::-1]
    B = [10**10]+B[::-1]

    a = 0
    while True:
        if A[-1] < B[-1] and K >= A[-1]:
            a += 1
            K -= A.pop()
        if K >= B[-1]:
            a += 1
            K -= B.pop()
        else:
            return a

print(hoge())
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

waa=[0 for i in range(n)]
waa[0]=a[0]
wab=[0 for i in range(m)]
wab[0]=b[0]
for i in range(1,n):
  waa[i]=waa[i-1]+a[i]
for i in range(1,m):
  wab[i]=wab[i-1]+b[i]

ans=0
for i in range(n):
  if waa[i]>k:
    break
  idx=bisect.bisect_left(wab,k-waa[i])
  if idx<m and wab[idx]==k-waa[i]:
    idx+=1
  ans=max(ans,i+idx+1)
print(ans)
na,nb,k = map(int, input().split())
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))


def get_bcnt( usek,tb=tb ):
    tb_sum = [ sum(tb[:i]) + tt for i, tt in enumerate(tb)]
    tb_sum_tf = [ i <= usek for i in tb_sum]
    
    if False in tb_sum_tf:
        return tb_sum_tf.index(False)
    else:
        return len(tb)
    
 
readbook = [ i+1 + get_bcnt( k - sum( ta[:i] ) )  for i in range(na) if sum( ta[:i] ) <= k ]
readbook.append( get_bcnt(k) )
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    d = 0
    for j in range(d, m):
        if a[i]+b[-j-1] <= k:
            c = max(c, i+m-j+1)
            d = j
            break;
print(c)
N, M, K = map(int, input().split())

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

m = 0
mnt = 0
num = 0
for i, a in enumerate(A):
    num = i+1
    if mnt + a > K:
        num = i
        break
    mnt += a
A = A[:num]
ans = num

j = 0
for i in range(num):
    while j < M and mnt+B[j] <= K:
        mnt += B[j]
        j += 1
        ans = max(ans, j+num-i)
    mnt -= A[num-i-1]
print(ans)
a = [input() for l in range(0,3)]
a1 = [int(p) for p in a[0].split()]
a2 = [int(p) for p in a[1].split()]
a3 = [int(p) for p in a[2].split()]
a4 = a2 + a3
b = sorted(a4)
c = 0
for i in range(0,len(b)):
    c = c + b[i]
if c <= a1[2]:
    print(len(b))
else:
    s = 0
    t = 0
    while s <= a1[2] and t < len(b):
        s = s + b[t]
        t = t + 1
    print(t-1)
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 = np.array(A)
B_np = np.array(B)

C_np = np.append(A_np,B_np)
C_np = np.sort(C_np)

x = 0
y = 0
for i in range(len(C_np)):
    if K >= x + C_np[i]:
        x += C_np[i]
        y += 1
    else:
        break
print(x)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(K + 1)
B.append(K + 1)
ia, ib = 0, 0
time = 0
flag = True
while flag:
    flag = False
    if A[ia] <= B[ib] and time + A[ia] <= K:
        time += A[ia]
        ia += 1
        flag = True
    elif B[ib] < A[ia] and time + B[ib] <= K:
        time += B[ib]
        ib += 1
        flag = True
print(ia + ib)
N, M, K = map(int, input().split())

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

C = A+B
C.sort()

ans = 0
count = 0
for c in C:
  ans += c
  if ans <= K:
    count += 1
  else:
    break

print(count)
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = min(m,n)
i = j = 0
ans = 0
while i < n and j < m:
  if A[i] < B[j]:
    k -= A[i]
    i += 1
  else: k -= B[j]; j += 1
  if k > 0: ans += 1
if i < n:
  for q in range(i,n):
    k -= A[q]
    if k >= 0: ans += 1
    else: print(ans);exit()
elif j < m:
  for q in range(j,m):
    k -= B[q]
    if k >= 0: ans += 1
    else: print(ans); exit()
print(ans)
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(float("INF"))
b.append(float("INF"))
la = [a[0]]
lb = [b[0]]
for i in range(1,n):
    la.append(la[-1]+a[i])
for i in range(1,m):
    lb.append(lb[-1]+b[i])
ans = 0
for i in range(n):
    if la[i] > k:
        break
    x = k-la[i]

    count = i+1
    ind = bisect.bisect_right(lb,x)
    count += ind
    ans = max(ans,count)
print(ans)
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [0]+[int(x) for x in input().split()]

count = sum(a)
p = n-1
ans = 0
judge = True
for i in range(m+1):
  flag = False
  count += b[i]
  while count > k and judge:
    count -= a[p]
    p -= 1
    if p == -1:
      if count > k:
        flag = True
      else:
        judge = False
      break
  if flag:
    break
  sub = p+1+i
  if ans < sub:
    ans = sub
print(ans)
input_data = [input().split() for l in range(3)]

limit = int(input_data[0][2])
deskA = [int(m) for m in input_data[1]]
deskB = [int(m) for m in input_data[2]]
num = 0

while True:
  try:
    if not deskA:
      limit -= int(deskB.pop(0))
    elif not deskB:
      limit -= int(deskA.pop(0))
    elif deskA[0] >= deskB[0]:
      limit -= int(deskB.pop(0))
    else:
      limit -= int(deskA.pop(0))
    if limit < 0:
      break
    num += 1

  except IndexError:
    break

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

import numpy as np
C=np.array(sorted(A+B)).cumsum()

import bisect
print(bisect.bisect_left(C, K))
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])
print(a,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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] + list(reversed(b)) + a
for i in range(n + m):
    c[i + 1] += c[i]
r = m
ans = 0
for l in range(n + m):
    while r <= n + m and c[r] - c[l] <= k:
        ans = max(ans, r - l)
        r += 1
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

m = M+1
cost = []
for n in range(N + 1):
    print(n, m)
    if sum(A[:n]) > K:
        break
    while True:
        print(n, m)
        if sum(A[:n]) + sum(B[:m]) <= K:
            cost.append(n + m)
            break
        m -= 1

print(max(cost))
import collections as cs

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

A.append(K + 1)
B.append(K + 1)

count = 0
time = 0
num = len(A) + len(B)

for i in range(num):
    if A[0] <= B[0]:
        if A[0] + time <= K:
            time += A.popleft()
            count += 1

    elif A[0] > B[0]:
        if B[0] + time <= K:
            time += B.popleft()
            count += 1

print(count)
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(100000000000000000)
B.append(100000000000000000)
A.reverse()
B.reverse()


ans = 0
c = 0
while True:
  if A[-1] >= B[-1]:
    b = B.pop()
    if ans+b > X:
      break
    ans += b
    c += 1
  else:
    a = A.pop()
    if ans+a > X:
      break
    ans += a
    c += 1
print(c)
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
    sb[i+1] = sb[i] + b[i]

ans = 0
for i in range(1,n+1):
    bi = min(m, bisect.bisect_right(sb, max(0, k-sa[i]+1))-1)
    if sa[i] + sb[bi] <= k:
        ans = max(ans, i + bi)
print(ans)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

S_A = [0] * (N + 1)
S_B = [0] * (M + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
A.append(1000000000)
B = list(map(int, input().split()))
B.append(1000000000)
time = 0
numA = 0
numB = 0

while time < K:
    if A[numA] < B[numB]:
        time += A[numA]
        if time <= K:
            numA += 1
        else:
            break
    else:
        time += B[numB]
        if time <= K:
            numB += 1
        else:
            break

print(numA + numB)
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=a+[10**18]
b=b+[10**18]
ans,t=0,0
i,j=0,0
while t<=k:
    if i>=n and j>=m:
        break
    if a[i]<=b[j]:
        t+=a[i]
        i+=1
    else:
        t+=b[j]
        j+=1
    if t<=k:
        ans+=1
print(ans)
#print(t)
import numpy as np

def main():
  n,m,k=map(int,input().split())
  a=list(map(int,input().split()))
  b=np.array(list(map(int,input().split())))
  #a=np.cumsum(a)
  b=np.cumsum(b)
  k0=k+1
  #a0=np.searchsorted(a,k)
  b0=np.searchsorted(b,k)
  r=b0
  i=0
  for i, ia in enumerate(a):
    k0=k0-ia
    #print(k0)
    if k0<=0:
      break
    b0=np.searchsorted(b,k0)
    b0+=i+1
    if b0 > r:
      r=b0
  print(r)
main()
n, m, k =map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0

for i in range(n+1):
    ta -= a[n-i]
    for j in range(m):
        tb += b[j]
        if tb + ta >k:
            break
        if j==m-1:
            j +=1

    ans=max(ans,n-i+j)

print(ans)
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)
ans = 0
for i in range(len(A)):
    j = bisect_right(B, k-A[i]) - 1
    # if k >= A[i] + B[j]:
        # ans = max(ans, i+j)
    ans = max(ans, i+j)

# print(k)
# print(A)
# print(B)
print(ans)
N ,M ,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
result = 0

A.append(10**10)
B.append(10**10)
i,j = 0,0
for k in range(N+M):
    K -= min(A[i],B[j])
    if K < 0:
        break
    if A[i] <= B[j]:
        i += 1
    else:
        j += 1
    result += 1
print(result)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = 0
c = 0
while(t<k):
  if a[0] < b[0]:
    t += a.pop(0)
    c+=1
  else:
    t += b.pop(0)
    c+=1
  if a==[]:a.append(10**8)
  if b==[]:b.append(10**8)
  if a[0]==10**8 and b[0]==10**8:
    c+=1
    break  
print(c-1)
N, M, K = map(int, input().split())
pa = abs(N-M) + 1
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
while K >= A[0] or K >= B[0]:
    if A[0] < B[0]:
        K -= A.pop(0)
    else:
        K -= B.pop(0)
    c += 1
    if len(A) == 0:
        A = A + [1000000010]
    if len(B) == 0:
        B = B + [1000000010]
print(c)
n,m,k=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.append(10000000000000000)
B.append(10000000000000000)
a=0
b=0
cnt=0
for i in range(n+m):
	if a==n and k>=B[b]:
		k-=B[b]
		cnt+=1
		b+=1
	elif b==m and k>=A[a]:
		k-=A[a]
		cnt+=1
		a+=1	
	elif min(A[a],B[b])>k:
		break 
	elif A[a]>=B[b]:
		k-=B[b]
		b+=1
		cnt+=1
	else:
		k-=A[a]
		a+=1
		cnt+=1
print(cnt)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dp_A = [0]*N
dp_B = [0]*M
dp_A[0] = A[0]
dp_B[0] = B[0]

for a in range(1, N):
    dp_A[a] += dp_A[a-1] + A[a]

for b in range(1, M):
    dp_B[b] += dp_B[b-1] + B[b]
ans = 0
for i in range(N):
    for j in range(M):
        if dp_A[i] + dp_B[j] <= K:
            ans = max(ans, i+j+2)
print(ans)
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, m, k = inm()
a = inl()
b = inl()
count = 0
for i in range(n-1):
    a[i+1] += a[i]
for i in range(m-1):
    b[i+1] += b[i]
for i in range(n):
    j = m-1
    if a[i] > k:
        break
    while a[i] + b[j] > k and j >= 0:
        j -= 1
    count = max(count, i+j + 2)
print(count)
a,b,c = (int(i) for i in input().split())
N = list(int(a) for a in input().split())
M = list(int(b) for b in input().split())
total = 0
n = 0
m = 0
e = 0
for i in range(a+b):
  if N[n] < M[m] and n < a:
    c -= N[n]
    e += 1
  elif N[n] > M[m] and m < a:
    c -= M[m]
    e += 1
  elif n == a:
    c -= M[m]
    e += 1
  elif m == a:
    c -= N[n]
    e += 1

  if c < 0:
    e -= 1
    break

print(e)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]*n
ba=[0]*m
aa[0]=a[0]
ba[0]=b[0]
for i in range(1,n):
  aa[i]=aa[i-1]+a[i]
for i in range(1,m):
  ba[i]=ba[i-1]+b[i]
aa=[0]+aa
ba=[0]+ba
import bisect as bi
ax=bi.bisect_right(aa,k)-1
ans=0
for i in range(ax):
  kk=k-aa[ax-i]
  bx=bi.bisect_right(ba,kk)-1
  t=ax+bx-i
  ans=max(ans,t)
print(ans)
n,m,k = map(int,input().split())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))

t = 0
i = 0
j = 0
while (t <= k):
  #print(i,j,t)
  if i < n:
    ai = a[i]
  else:
    ai = 10**10
  if j < m:
    bi = b[j]
  else:
    bi = 10**10
  if ai < bi:
    i += 1
    t += ai
  else:
    j += 1
    t += bi
print(i+j-1)
x, y, z = map(int, input().split())
lx = list(map(int, input().split()))
nx = lx[0]
ly = list(map(int, input().split()))
ny = ly[0]
a = 0

while nx <= z or ny <= z:
  if nx <= ny:
    z = z-nx
    lx.pop(0)
    if not lx:
      nx = z+1  
    else:
      nx = lx[0]
    a = a+1
  else:
    z = z-ny
    ly.pop(0)
    if not ly:
      ny = z+1
    else:
      ny = ly[0]
    a = a + 1  
print(a)
n,m,k=map(int,input().split())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
from collections import deque
As=deque(As)
Bs=deque(Bs)
ans=0
inf=100000000000000000000000000000000000
while k>0:
    try:
        a=As.popleft()
    except:
        a=inf
    try:
        b=Bs.popleft()
    except:
        b=inf
    if a>b:
        k-=b
        As.appendleft(a)
    else:
        k -=a
        Bs.appendleft(b)
    ans+=1
print(ans-1)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
    if m == 0:
        break;
print(c)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]*n
B=[0]*m
A[0]=a[0]
B[0]=b[0]
ans=0

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

for j in range(n):
  K=k-A[j]
  if K<0:
    break
  left=0
  right=m
  while left<right:
    mid=(left+right)//2
    if B[mid]>K:
      right=mid
    else:
      left=mid+1
  ans=max(ans,j+left+1)
print(ans)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+1):
  if a[i] > K:
    break
  for j in range(M+1):
    if a[i]+b[M-j] < K:
      ans = max(ans,i+M-j)
      break

print(ans)
from itertools import accumulate

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

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

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

C = list(accumulate(A))

D = list(accumulate(B))

res = 0
for i,v1 in enumerate(C,1):
  for j,v2 in enumerate(D,1):
    if v1+v2 <= K:
      res = max(res,i+j)
    else:
      break

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

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

from heapq import heapify, heappop, heappush

heap = []
heapify(heap)

for a in A:
    heappush(heap, a)
for b in B:
    heappush(heap, b)

cnt = 0
t = 0
while t < K:
    x = heappop(heap)
    t += x

    if t <= K:
        cnt += 1

print(cnt)
import bisect
n, m, lim = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = [0] * (n+m+1)
nowt = 0
acnt = 0
bcnt = 0

a.append(10**9+1)
b.append(10**9+1)
for i in range(1, n+m+1):
  if a[acnt] < b[bcnt]:
    s[i] = s[i-1] + a[acnt]
    acnt += 1
  else:
    s[i] = s[i-1] + b[bcnt]
    bcnt += 1

print(bisect.bisect_right(s, lim)-1)
import collections as deque

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A += B
A.sort()
hon = deque.deque(A)
time = 0
ans = 0

while len(hon) > 0:
    time += hon.popleft()
    if time <= K:
        ans += 1

print(ans)
import sys
readline = sys.stdin.readline

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

for i in range(1, len(A)):
  A[i] = A[i] + A[i - 1]
  
for i in range(1, len(B)):
  B[i] = B[i] + B[i - 1]
  
import bisect
ans = 0
for i in range(len(A)):
  rest = K - A[i]
  # あとrest分大丈夫
  ind = bisect.bisect_right(B, rest)
  if ind != 0:
    if (i + 1) + (ind) > ans:
      ans = (i + 1) + (ind)

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

minute = 0
num = 0
a = 0
b = 0
while(minute<K):
    if len(A[a:]) == 0:
        minute += B[b]
        b += 1 
    elif len(B[b:]) == 0:
        minute += A[a]
        a += 1
    elif A[a] < B[b]:
        minute += A[a]
        a += 1
    else:
        minute += B[b]
        b += 1
    
    if minute <= K:
        num += 1

print(num)
import sys
a, b, n = map(int, input().split())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
alis.append(sys.maxsize)
blis.append(sys.maxsize)

count = 0
time = 0

ac = 0
bc = 0
while time <= n:
    time += min(alis[ac], blis[bc])
    count += 1
    if alis[ac] < blis[bc]:
        ac += 1
    else:
        bc +=1

print(count-1)
from bisect import bisect_left

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

cumA = [0]
for i in range(N):
  cumA.append(cumA[-1]+A[i])
  
cumB = [0]
for i in range(M):
  cumB.append(cumB[-1]+B[i])
  
if cumA[-1]+cumB[-1]<=K:
  print(N+M)
  exit()
  
ans = 0
for i in range(N+1):
  if K-cumA[i]<=0:break
  idx = bisect_left(cumB,K-cumA[i])
  if idx == 0:
    res = i
  else:
    res = i+idx-1
  ans = max(ans, res)
  
print(ans)
import sys
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

ans = 0
for n in range(N-1):
    for m in range(M-1):
        if K < sum(A_list[:n+1]):
            print(ans)
            sys.exit()
        
        if K >= sum(A_list[:n+1])+sum(B_list[:m+1]):
            ans = max(ans, n+m+2)
        else:
            break
            
print(ans)
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
count = 0

for _ in range(99):
  if A[0] > k and B[0] > k:
    break
  if A[0] < B[0]:
    k -= A.pop(0)
    count += 1
  else:
    k -= B.pop(0)
    count += 1
  if len(A)==0:
    A.append((10**9)+1)
  if len(B)==0:
    B.append((10**9)+1)
print(count)
import bisect
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A_acc=[0]
B_acc=[0]

for a in A:
    A_acc.append(a+A_acc[-1])
for b in B:
    B_acc.append(b+B_acc[-1])

ans=0
for i in range(len(A_acc)):
    a_time = A_acc[i]
    remain = K-a_time
    if remain>0:
        idx = bisect.bisect_right(B_acc,remain)
        ans=max(ans,i+idx-1)
print(ans)
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N,M,K=MI()
A=[0]+LI()
B=[0]+LI()
from itertools import accumulate
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
for i in range(1,N+1):
  if A[i]>K:
    continue
  for j in range(M,-1,-1):
    if A[i]+B[j]>K:
      continue
    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()))

total = 0
len_A = len(A)
len_B = len(B)
i = 0
j = 0
while True:
  a_i = A[i] if i < len_A else 1e10
  b_j = B[j] if j < len_B else 1e10
  if i >= len_A and j >= len_B:
    break
  if a_i < b_j:
    K -= float(a_i)
    i += 1
  else:
    K -= float(b_j)
    j += 1
  if K >= 0 - 1e-2:
    total += 1
  else:
    break
    
print(total)
n,m,k = map(int,input().split())
c = []
a = list(map(int,input().split()))
for x in a:
    c.append(x)
b = list(map(int,input().split()))
for x in b:
    c.append(x)
c.sort()
cc = 0
ans = 0
for x in c:
    cc += x
    ans = ans + 1
    if cc >= k:
        if cc > k:
            print(ans-1)
            break
        else:
            print(ans)
            break
    else:
        pass
N,M,K = map(int,input().split())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
count = 0
output = 0
for i in range(N):
    count += A_list[i]
    if count > K:
        break
for j in range(i + 1):
    alcount = sum(A_list[:j + 1])
    for h in range(M):
        alcount += B_list[h]
        if alcount > K:
            break
        if j + h + 2 > output:
            output = j + h + 2
    
#        print(j,h,alcount)
print(output)
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]+a[i]> K:
        j -= 1
    ans = max(ans, i + j)
print(ans)
print(a)
print(b)
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)
        sys.exit()
import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

left_max = bisect.bisect_left(cost_a, k)

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

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if ra[i]<0:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,i-1+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=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

asum=[0]
bsum=[0]

for i in range(n):
  asum.append(asum[i]+A[i])
  
for j in range(m):
  bsum.append(bsum[j]+B[j])

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