const main = (input) => {
  input = input.trim().split('\n')
  const [N, M, K] = input[0].split(' ').map(BigInt)
  const booksA = input[1].split(' ').map(BigInt)
  const booksB = input[2].split(' ').map(BigInt)

  let currentSum = 0n
  const maxB = []
  for (let i = 0; i < booksB.length; i++) {
    currentSum += booksB[i]
    maxB.push(booksB[i])

    if (currentSum > K) {
      currentSum -= maxB.pop()
      break
    }
  }

  let ans = maxB.length

  let A_sum = 0n
  const Alist = []
  for (let i = 0; i < booksA.length; i++) {
    A_sum += booksA[i]
    Alist.push(booksA[i])

    while (A_sum + currentSum > K && maxB.length) currentSum -= maxB.pop()
    if (A_sum + currentSum > K) break

    ans = Math.max(ans, Alist.length + maxB.length)
  }

  return console.log(ans)
}


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