func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func binarySearch(_ inputArray: [Int], _ searchItem: Int) -> Int {
    if inputArray[inputArray.count - 1] < searchItem {
      return inputArray.count
    }
  
    var lowerIndex = 0
    var upperIndex = inputArray.count
    
    while true {
        let currentIndex = (lowerIndex + upperIndex) / 2
        
        if inputArray[currentIndex] == searchItem {
            return currentIndex
        }
        if lowerIndex == currentIndex {
            if inputArray[upperIndex] == searchItem {
                return upperIndex
            } else {
                return currentIndex
            }
        }
        
        if inputArray[currentIndex] > searchItem {
            upperIndex = currentIndex
        } else {
            lowerIndex = currentIndex
        }
    }
}

func main() {
    let line = readInts()
    // let n = line[0]
    // let m = line[1]
    let k = line[2]
    let a_tachi = readInts()
    let b_tachi = readInts()
    
    var a_acc: [Int] = [0]
    var b_acc: [Int] = [0]
    
    for i in 1...a_tachi.count {
        a_acc.append(a_acc[i - 1] + a_tachi[i - 1])
    }
    
    for j in 1...b_tachi.count {
        b_acc.append(b_acc[j - 1] + b_tachi[j - 1])
    }
    
    var ans = 0
    for j in 0...b_tachi.count {
        if b_acc[j] > k {
            break
        }
        let bookCount = j + binarySearch(a_acc, k - b_acc[j])
        if ans < bookCount {
            ans = bookCount
        }
    }
    
    print(ans)
}

main()
