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
})

var count: Int = sumB.firstIndex(where: {$0 > K}) ?? M

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