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

var sumAN: [Int] = [0]
for i in 0..<AN.count {
    sumAN.append(sumAN[i] + AN[i])
}
var sumBM: [Int] = [0]
for i in 0..<BM.count {
    sumBM.append(sumBM[i] + BM[i])
}

var bIndex = sumBM.count - 1

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