func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

let max = 10000000000
let line = readIntArray()
let (N, M, K) = (line[0], line[1], line[2])

let A = readIntArray()
let B = readIntArray()

var sum = 0
var sumA: [Int] = []
A.forEach({
    sumA.append($0 + sum)
    sum += $0
})

sum = 0
var sumB : [Int] = []
B.forEach({
    sumB.append($0 + sum)
    sum += $0
})

func findIndex(time: Int) -> Int {
    var left = -1
    var right = sumB.count
    while left < right - 1 {
        let mid = (left + right) / 2
        if sumB[mid] <= time {
            left = mid
        } else {
            right = mid
        }
    }
    return left + 1
}

var count: Int = findIndex(time: K)

for i in 0..<N {
    let time = K - sumA[i]
    if time < 0 {
        break
    }
    let temp: Int = i + 1 + findIndex(time: time)
    if temp > count {
        count = temp
    }
}
print(count)

