const [nmk, _a, _b] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
let [n, m, k] = nmk.split(/\s/).map(Number)
const a = _a.split(/\s/).map(Number).reduce((acc, curr, i) => {
  acc[i] = curr + (i && acc[i - 1])
  return acc
}, [])
const b = _b.split(/\s/).map(Number).reduce((acc, curr, i) => {
  acc[i] = curr + (i && acc[i - 1])
  return acc
}, [])

let bIndex = binarySearch(b)
let result = bIndex + 1
for (let i = 0; i < a.length; i++) {
  const remaining = k - a[i]
  if (remaining < 0) {
    break
  }
  for (; bIndex >= 0; bIndex--) {
    if (b[bIndex] <= remaining) {
      break;
    }
  }
  result = Math.max(result, i + bIndex + 2)
}
console.log(result)

function binarySearch(arr) {
  let s = 0, e = arr.length - 1
  while (s < e) {
    const m = (s + e) >> 1
    const ml = arr[m] <= k, mu = arr[m + 1] <= k
    if (ml === mu) {
      if (ml) {
        s = m + 1
      } else {
        e = m - 1
      }
    } else {
      return m;
    }
  }
  return arr[s] <= k ? s : s - 1
}