# Original solution
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

timeleft = K
counter = 0

flag = True
while flag:
    if len(A) == 0 and len(B) == 0:
        flag = False
    elif len(A) == 0:
        if B[0] <= timeleft:
            counter += 1
            timeleft -= B[0]
            B.pop(0)
        else:
            flag = False
    elif len(B) == 0:
        if A[0] <= timeleft:
            counter += 1
            timeleft -= A[0]
            A.pop(0)
        else:
            flag = False
    elif len(A) == 1 and len(B) == 1:
        if A[0] < B[0]:
            if A[0] <= timeleft:
                counter += 1
                timeleft -= A[0]
                A.pop(0)
            else:
                flag = False
        else:
            if B[0] <= timeleft:
                counter += 1
                timeleft -= B[0]
                B.pop(0)
            else:
                flag = False
    elif len(A) == 1:
        if A[0] < B[0]:
            if A[0] <= timeleft:
                counter += 1
                timeleft -= A[0]
                A.pop(0)
            else:
                flag = False
        else:
            if B[0] <= timeleft:
                counter += 1
                timeleft -= B[0]
                B.pop(0)
            else:
                flag = False
    elif len(B) == 1:
        if B[0] < A[0]:
            if B[0] <= timeleft:
                counter += 1
                timeleft -= B[0]
                B.pop(0)
            else:
                flag = False
        else:
            if A[0] <= timeleft:
                counter += 1
                timeleft -= A[0]
                A.pop(0)
            else:
                flag = False 
    else:
        if A[0] < B[0]:
            if B[0] <= timeleft:
                if A[0] + A[1] < B[0] + B[1]:
                    timeleft -= A[0]
                    counter += 1
                    A.pop(0)
                else:
                    timeleft -= B[0]
                    counter += 1
                    B.pop(0)
            elif A[0] <= timeleft:
                timeleft -= A[0]
                counter += 1
                A.pop(0)
            else:
                flag = False
        else:
            if A[0] <= timeleft:
                if B[0] + B[1] < A[0] + A[1]:
                    timeleft -= B[0]
                    counter += 1
                    B.pop(0)
                else:
                    timeleft -= A[0]
                    counter += 1
                    A.pop(0)
            elif B[0] <= timeleft:
                timeleft -= B[0]
                counter += 1
                B.pop(0)
            else:
                flag = False
print(counter)

# Optimized solution
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

Asum = [0]
Bsum = [0]
atemp = 0
btemp = 0
for i in range(N):
    atemp += A[i]
    Asum.append(atemp)
for i in range(M):
    btemp += B[i]
    Bsum.append(btemp)

ans = 0
j = M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
        j -= 1
    ans = max(ans, i+j)

print(ans)