import Foundation

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

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

extension Optional {
    func pleaseAC(){
        print(self!)
    }
}

readLine().map { line -> Any in 
    var nmk = line.split(separator: " ").compactMap { Int($0) }.makeIterator()
    let n = *nmk
    let m = *nmk
    let k = *nmk
    
    let A = readWords { Int($0) }
    let 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 ""
    }

    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)
    }
    
    return ans
}
.pleaseAC()
