let NMK: [Int64] = readLine()!.split(separator: " ").map { Int64($0)! }
let As: [Int64] = readLine()!.split(separator: " ").map { Int64($0)! }
let Bs: [Int64] = readLine()!.split(separator: " ").map { Int64($0)! }

var time: Int64 = 0
var readed: Int = 0
var res: Int = 0

for A in As {
    time += A
    if time > NMK[2] { break }
    readed += 1
}
let aReaded: Int = readed

time = 0
readed = 0
for B in Bs {
    time += B
    if time > NMK[2] { break }
    readed += 1
}
let bReaded: Int = readed

let pref: Int = aReaded < bReaded ? 1 : 0
res = max(aReaded, bReaded)

for i in 0..<min(aReaded, bReaded) {
    if pref == 0 {
        var remainTime: Int64 = NMK[2] - As[0..<aReaded-i].reduce(0, +)
        var j: Int = 0
        while j < Bs.count && remainTime-Bs[j] >= 0 {
            remainTime -= Bs[j]
            j += 1
        }
        res = max(res, aReaded-i+j)
    } else {
        var remainTime: Int64 = NMK[2] - Bs[0..<bReaded-i].reduce(0, +)
        var j: Int = 0
        while j < As.count && remainTime-As[j] >= 0  {
            remainTime -= As[j]
            j += 1
        }
        res = max(res, bReaded-i+j)
    }
}
print(res)  // (๑•ૅㅁ•๑)