import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import deque

def main():

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

    A = [int(i) for i in readline().split()]

    B = [int(i) for i in readline().split()]



    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める

    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。



    csumA = [0]

    for i in range(N):

        csumA.append(csumA[i] + A[i])



    csumB = [0]

    for i in range(M):

        csumB.append(csumB[i] + B[i])



    mx = 0

    for i in range(N+1):

        # r:= Aの山の上からi番目までの本を読むとき、残りの時間

        r = K-csumA[i]

        if r < 0:

            break

        left = -1

        right = M+1

        while right-left>1: 

            mid = (left+right)//2

            if r >= csumB[mid]:

                left = mid

            else:

                right = mid



        mx = max(mx, i+left)

    print(mx)



if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import deque

def main():

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

    A = [int(i) for i in readline().split()]

    B = [int(i) for i in readline().split()]



    ca = [0]

    cb = [0]

    for i in range(N):

        ca.append(ca[i] + A[i])

    for i in range(M):

        cb.append(cb[i] + B[i])



    ans = 0  

    j = M

    for i in range(N+1):

        if K < ca[i]:

            break

        while cb[j] > K-ca[i]:

            j -= 1

        ans = max(ans, i+j)

    print(ans)

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


def main():
    N, M, K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    # 方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    # A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。
    csumA = [0]
    for i in range(N):
        csumA.append(csumA[i] + A[i])
    csumB = [0]
    for i in range(M):
        csumB.append(csumB[i] + B[i])
    mx = 0
    for i in range(N + 1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        r = K - csumA[i]
        if r < 0:
            break
        left = -1
        right = M + 1
        while right - left > 1:
            mid = (left + right) // 2
            if r >= csumB[mid]:
                left = mid
            else:
                right = mid
        mx = max(mx, i + left)
    print(mx)


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


def main():
    N, M, K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    ca = [0]
    cb = [0]
    for i in range(N):
        ca.append(ca[i] + A[i])
    for i in range(M):
        cb.append(cb[i] + B[i])
    ans = 0
    j = M
    for i in range(N + 1):
        if K < ca[i]:
            break
        while cb[j] > K - ca[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__ == "__main__":
    main()

-    # 方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める -    # A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。 -    csumA = [0] +    ca = [0] +    cb = [0] -        csumA.append(csumA[i] + A[i]) -    csumB = [0] +        ca.append(ca[i] + A[i]) -        csumB.append(csumB[i] + B[i]) -    mx = 0 +        cb.append(cb[i] + B[i]) +    ans = 0 +    j = M -        # r:= Aの山の上からi番目までの本を読むとき、残りの時間 -        r = K - csumA[i] -        if r < 0: +        if K < ca[i]: -        left = -1 -        right = M + 1 -        while right - left > 1: -            mid = (left + right) // 2 -            if r >= csumB[mid]: -                left = mid -            else: -                right = mid -        mx = max(mx, i + left) -    print(mx) +        while cb[j] > K - ca[i]: +            j -= 1 +        ans = max(ans, i + j) +    print(ans)