import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {

    fun PrintWriter.solve() {
        var (n,m,k) = List(3){nextInt()}
        var A = LongArray(n+1){0}
        var B = LongArray(m+1){0}

        for (i in 1..n){
            A[i] = A[i-1] + nextInt()
        }

        for (i in 1..m){
            B[i] = B[i-1] + nextInt()
        }

        var ans = 0

        for (i in 0..n){


            var (l,r) = listOf(0,m)
            while (l <= r){
                var mid = (l+r)/2
                var nval = A[i] + B[mid]

                if (nval <= k){
                    ans = maxOf(ans,i+mid)
                    l = mid+1
                }
                else{
                    r = mid-1
                }

            }



        }

        println(ans)





    }

    writer.solve()
    writer.flush()


}


private val reader = System.`in`.bufferedReader()
private val writer = PrintWriter(System.out, false)

private var tokenizer: StringTokenizer = StringTokenizer("")

private fun next(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextLine() = reader.readLine()

