import itertools as it

def main():

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

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

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

    a, b = [0],[0]

    for i in range(n):

        a.append(a[i] + Aa[i])

    for i in range(m):

        b.append(b[i] + Bb[i])

    M = m

    ans = 0

    for A in range(n+1):

        aa = a[A]

        Kaa = k-aa

        if Kaa < 0:

            break

        for B in range(M,-1,-1):

            if b[B] <= Kaa:

                ans = max(ans, A+B)

                M = B

                break

    print(ans)



if __name__ == '__main__':

    main()
import itertools as it

def main():

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

    a = [0]

    a.extend(it.accumulate(list(map(int, input().split()))))

    b = [0]

    b.extend(it.accumulate(list(map(int, input().split()))))

    

    ans = 0

    M = m

    for A in range(n+1):

        aa = a[A]

        Kaa = k-aa

        if Kaa < 0:

            break

        for B in range(M,-1,-1):

            if b[B] <= Kaa:

                ans = max(ans, A+B)

                M = B

                break

    print(ans)



if __name__ == '__main__':

    main()
import itertools as it


def main():
    n, m, k = list(map(int, input().split()))
    Aa = list(map(int, input().split()))
    Bb = list(map(int, input().split()))
    a, b = [0], [0]
    for i in range(n):
        a.append(a[i] + Aa[i])
    for i in range(m):
        b.append(b[i] + Bb[i])
    M = m
    ans = 0
    for A in range(n + 1):
        aa = a[A]
        Kaa = k - aa
        if Kaa < 0:
            break
        for B in range(M, -1, -1):
            if b[B] <= Kaa:
                ans = max(ans, A + B)
                M = B
                break
    print(ans)


if __name__ == "__main__":
    main()

import itertools as it


def main():
    n, m, k = list(map(int, input().split()))
    a = [0]
    a.extend(it.accumulate(list(map(int, input().split()))))
    b = [0]
    b.extend(it.accumulate(list(map(int, input().split()))))
    ans = 0
    M = m
    for A in range(n + 1):
        aa = a[A]
        Kaa = k - aa
        if Kaa < 0:
            break
        for B in range(M, -1, -1):
            if b[B] <= Kaa:
                ans = max(ans, A + B)
                M = B
                break
    print(ans)


if __name__ == "__main__":
    main()

-    Aa = list(map(int, input().split())) -    Bb = list(map(int, input().split())) -    a, b = [0], [0] -    for i in range(n): -        a.append(a[i] + Aa[i]) -    for i in range(m): -        b.append(b[i] + Bb[i]) +    a = [0] +    a.extend(it.accumulate(list(map(int, input().split())))) +    b = [0] +    b.extend(it.accumulate(list(map(int, input().split())))) +    ans = 0 -    ans = 0