const main = (input) => {
  input = input.trim().split('\n')
  const [n, m, k] = input[0].split(' ').map(Number)
  const a = input[1].split(' ').map(Number)
  const b = input[2].split(' ').map(Number)

  let ans = 0

  const a_read = [], b_read = []
  let a_sum = 0, b_sum = 0

  while (b.length && b_sum + b[0] <= k) {
    const book = b.shift()
    b_read.push(book)
    b_sum += book
  }

  while (a.length) {
    const book = a.shift()
    a_read.push(book)
    a_sum += book

    while (a_sum + b_sum > k && b_read.length) b_sum -= b_read.pop()

    if (a_sum + b_sum > k) return console.log(ans)

    ans = Math.max(ans, a_read.length + b_read.length)
  }

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))