import Foundation

private func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

prefix operator *
private prefix func *<T>(a: inout IndexingIterator<[T]>) -> T {
    return a.next()!
}

func mainC() {
    var nmk = readWords { Int($0)! }.makeIterator()
    let n = *nmk
    let m = *nmk
    var k = *nmk
    
    var A = readWords { Int($0)! }
    var B = readWords { Int($0)! }
    
    var cumA = [Int]()
    cumA.append(0)
    var cumB = [Int]()
    var totalA = 0
    for a in A {
        let x = totalA + a
        if x > k {
            break
        }
        cumA.append(x)
        totalA = x
    }
    
    var totalB = 0
    for b in B {
        let x = totalB + b
        if x > k {
            break
        }
        cumB.append(x)
        totalB = x
    }
    
    if cumA.count == 1 && cumB.isEmpty {
        print(0)
        return
    }
    
    if cumA.count == 1 {
        print(cumB.count)
        return
    }
    
    if cumB.isEmpty {
        print(cumA.count)
        return
    }
    
    // 先に読んでしまった方がいい場合がある
    // 貪欲じゃない
    // 希望的観測
    // AのKを超えない範囲
    // BのKを超えない範囲
    // 累積和をとる
    // その中から最大の個数を取得
    // 二分探索?
    
    // Aを固定してBの位置を決める
    var ans = 0
    for (i, a) in cumA.enumerated() {
        var l = -1
        var r = cumB.count
        while r - l > 1 {
            let mid = l + (r - l) / 2
            if cumB[mid] + a > k {
                r = mid
            } else {
                l = mid
            }
        }
        ans = max(ans, i+r)
    }
    
    print(ans)
    

}

mainC()
