import sys

import numpy as np

input = lambda: sys.stdin.readline().rstrip()



def main():

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

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

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

  sa = np.cumsum([0]+a)

  sb = np.cumsum([0]+b)

  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

import numpy as np

input = lambda: sys.stdin.readline().rstrip()



def main():

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

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

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

  sa = np.cumsum([0]+a)

  sb = np.cumsum([0]+b)

  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
import numpy as np

input = lambda: sys.stdin.readline().rstrip()


def main():
    n, m, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    sa = np.cumsum([0] + a)
    sb = np.cumsum([0] + b)
    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
import numpy as np

input = lambda: sys.stdin.readline().rstrip()


def main():
    n, m, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    sa = np.cumsum([0] + a)
    sb = np.cumsum([0] + b)
    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()

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