let NMK = readLine()!.split(separator: " ").compactMap { Int($0) }
let k = NMK[2]
let AN = readLine()!.split(separator: " ").compactMap { Int($0) }
let BM = readLine()!.split(separator: " ").compactMap { Int($0) }

let sumAN = AN.reduce([Int]()) { $0 + [($0.last ?? 0) + $1] }
let sumBM = BM.reduce([Int]()) { $0 + [($0.last ?? 0) + $1] }

var bIndex = sumBM.count - 1

// Caluculate maximized count on each sumA
let maxCountList = sumAN.enumerated().reversed().map { sumA -> Int in
    while sumA.element + sumBM[bIndex] > k {
        if bIndex == 0 {
            return 0
        } else {
            bIndex -= 1
        }
    }
    return sumA.offset + bIndex + 2
}
print(maxCountList.max() ?? 0)
