import sys

input = sys.stdin.readline



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

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

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

rx = 0

rb = m

for ra in range(0,n+1): 

  while (sb[rb] + sa[ra]) > k and rb>0 :

    rb-=1

  if (sb[rb] + sa[ra]) <= k:

    rx = max(rx,ra+rb)

print(rx)

import sys

input = sys.stdin.readline



def main():

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

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

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

  rx = 0

  rb = m

  for ra in range(0,n+1): 

    while (sb[rb] + sa[ra]) > k and rb>0 :

      rb-=1

    if (sb[rb] + sa[ra]) <= k:

      rx = max(rx,ra+rb)

  print(rx)



if __name__ == '__main__':

    main()
import sys

input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().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]
rx = 0
rb = m
for ra in range(0, n + 1):
    while (sb[rb] + sa[ra]) > k and rb > 0:
        rb -= 1
    if (sb[rb] + sa[ra]) <= k:
        rx = max(rx, ra + rb)
print(rx)

import sys

input = sys.stdin.readline


def main():
    n, m, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().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]
    rx = 0
    rb = m
    for ra in range(0, n + 1):
        while (sb[rb] + sa[ra]) > k and rb > 0:
            rb -= 1
        if (sb[rb] + sa[ra]) <= k:
            rx = max(rx, ra + rb)
    print(rx)


if __name__ == "__main__":
    main()

-n, m, k = list(map(int, input().split())) -a = list(map(int, input().split())) -b = list(map(int, input().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] -rx = 0 -rb = m -for ra in range(0, n + 1): -    while (sb[rb] + sa[ra]) > k and rb > 0: -        rb -= 1 -    if (sb[rb] + sa[ra]) <= k: -        rx = max(rx, ra + rb) -print(rx) + + +def main(): +    n, m, k = list(map(int, input().split())) +    a = list(map(int, input().split())) +    b = list(map(int, input().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] +    rx = 0 +    rb = m +    for ra in range(0, n + 1): +        while (sb[rb] + sa[ra]) > k and rb > 0: +            rb -= 1 +        if (sb[rb] + sa[ra]) <= k: +            rx = max(rx, ra + rb) +    print(rx) + + +if __name__ == "__main__": +    main()