import sys

#import numpy as np

#from collections import defaultdict

import math

#from collections import deque



#input = sys.stdin.readline

#import numpy as n

import bisect







def main():



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



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

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

    cumA=[0]*(len(A)+1)

    cumB = [0] * (len(B)+1)

    tempA=0

    for i in range(1,len(A)+1):

        cumA[i]=tempA+A[i-1]

        tempA+= A[i-1]

    tempB = 0

    for i in range(1,len(B)+1):

        cumB[i] = tempB + B[i-1]

        tempB+= B[i-1]

#    print(cumB)

    ans =0

    for i in range(len(A)+1):

        res = K - cumA[i]

        if res<0:

            break

        b_read = bisect.bisect_right(cumB,res)

        ans =max( i + b_read,ans)

 #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))



    print((ans-1))





if __name__ == "__main__":

    main()
import sys

#import numpy as np

#from collections import defaultdict

import math

#from collections import deque



#input = sys.stdin.readline

#import numpy as n

import bisect







def main():



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



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

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

    cumA=[0]*(len(A)+1)

    cumB = [0] * (len(B)+1)

    tempA=0

    for i in range(1,len(A)+1):

        cumA[i]=tempA+A[i-1]

        tempA+= A[i-1]

    tempB = 0

    for i in range(1,len(B)+1):

        cumB[i] = tempB + B[i-1]

        tempB+= B[i-1]

#    print(cumB)

    ans =0

    j = M

    for i in range(len(A)+1):

        res = K - cumA[i]

        if res<0:

            break

        while cumB[j] + cumA[i] > K:

            j -=1

        ans = max(ans, i + j)

 #       b_read = bisect.bisect_right(cumB,res)

#        ans =max( i + b_read,ans)

 #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))



    print(ans)





if __name__ == "__main__":

    main()

import sys

# import numpy as np
# from collections import defaultdict
import math

# from collections import deque
# input = sys.stdin.readline
# import numpy as n
import bisect


def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cumA = [0] * (len(A) + 1)
    cumB = [0] * (len(B) + 1)
    tempA = 0
    for i in range(1, len(A) + 1):
        cumA[i] = tempA + A[i - 1]
        tempA += A[i - 1]
    tempB = 0
    for i in range(1, len(B) + 1):
        cumB[i] = tempB + B[i - 1]
        tempB += B[i - 1]
    #    print(cumB)
    ans = 0
    for i in range(len(A) + 1):
        res = K - cumA[i]
        if res < 0:
            break
        b_read = bisect.bisect_right(cumB, res)
        ans = max(i + b_read, ans)
    #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))
    print((ans - 1))


if __name__ == "__main__":
    main()

import sys

# import numpy as np
# from collections import defaultdict
import math

# from collections import deque
# input = sys.stdin.readline
# import numpy as n
import bisect


def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cumA = [0] * (len(A) + 1)
    cumB = [0] * (len(B) + 1)
    tempA = 0
    for i in range(1, len(A) + 1):
        cumA[i] = tempA + A[i - 1]
        tempA += A[i - 1]
    tempB = 0
    for i in range(1, len(B) + 1):
        cumB[i] = tempB + B[i - 1]
        tempB += B[i - 1]
    #    print(cumB)
    ans = 0
    j = M
    for i in range(len(A) + 1):
        res = K - cumA[i]
        if res < 0:
            break
        while cumB[j] + cumA[i] > K:
            j -= 1
        ans = max(ans, i + j)
    #       b_read = bisect.bisect_right(cumB,res)
    #        ans =max( i + b_read,ans)
    #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))
    print(ans)


if __name__ == "__main__":
    main()

+    j = M -        b_read = bisect.bisect_right(cumB, res) -        ans = max(i + b_read, ans) +        while cumB[j] + cumA[i] > K: +            j -= 1 +        ans = max(ans, i + j) +    #       b_read = bisect.bisect_right(cumB,res) +    #        ans =max( i + b_read,ans) -    print((ans - 1)) +    print(ans)