const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const [N, M, K] = lines[0].split(' ').map(Number)
    const A = lines[1].split(' ').map(Number)
    const B = lines[2].split(' ').map(Number)

    const a = []
    a[0] = 0
    for (let i = 0; i < N; i++) {
        a[i + 1] = a[i] + A[i]
        if (a[i + 1] > K) {
            a.pop()
            break
        }
    }

    const b = []
    b[0] = 0
    for (let i = 0; i < M; i++) {
        b[i + 1] = b[i] + B[i]
        if (b[i + 1] > K) {
            b.pop()
            break
        }
    }

    let dp = Array(N + M).fill(Infinity)

    let count =  0

    for (let i = a.length - 1; i >= 0; i--) {
        for (let j = 0; j < b.length; j++) {     
            if (a[i] + b[j] > K) {
                count = Math.max(count, i + j - 1)
                break
            } else {
                count = Math.max(count, i + j)
            }
        }
    }

    console.log(count)

})(input)
