use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i64,
        a: [i64; n],
        b: [i64; m],
    }

    let mut a_sum = vec![0];
    for ai in a.iter().copied() {
        let last = *a_sum.last().unwrap();
        a_sum.push(last + ai)
    }

    let mut b_sum = vec![0];
    for bi in b.iter().copied() {
        let last = *b_sum.last().unwrap();
        b_sum.push(last + bi)
    }
    // dbg!(&b_sum);

    // fn print_typename<T>(_: T) {
    //     println!("{}", std::any::type_name::<T>());
    // }
    // print_typename(&a_sum);
    // print_typename(&b_sum);

    let mut max = 0usize;
    for ia in 0..=n {
        let asi = a_sum[ia];
        // dbg!(asi);

        let ib = b_sum.binary_search_right(|bsi| asi + bsi <= k);
        if let Some(ib) = ib {
            // dbg!(ia, ib);
            max = std::cmp::max(ia + ib, max);
        }
    }
    println!("{}", max);

    // let mut a = a;
    // a.reverse();
    // let mut b = b;
    // b.reverse();

    // let mut time = 0;
    // let mut count = 0i64;
    // loop {
    //     let x = a.pop();
    //     let y = b.pop();

    //     match (x, y) {
    //         (Some(x), Some(y)) => {
    //             if x < y {
    //                 time += x;
    //                 b.push(y);
    //             } else {
    //                 time += y;
    //                 a.push(x);
    //             }
    //         },
    //         (Some(x), None) => {
    //             time += x;
    //         },
    //         (None, Some(y)) => {
    //             time += y;
    //         },
    //         (None, None) => {
    //             break;
    //         }
    //     }

    //     if time > k {
    //         break;
    //     }

    //     count += 1;
    // }

    // println!("{}", count);
}

trait BinarySearch<T, F> {
    fn binary_search_right(&self, condition: F) -> Option<usize>;
    fn binary_search_left(&self, condition: F) -> Option<usize>;
}

impl<T, F> BinarySearch<T, F> for Vec<T>
where
    F: Fn(&T) -> bool,
{
    fn binary_search_right(&self, condition: F) -> Option<usize> {
        if self.is_empty() {
            return None;
        }

        let len = self.len();
        if condition(&self[len - 1]) {
            return Some(len - 1);
        }
        if !condition(&self[0]) {
            return None;
        }

        let mut left = 0;
        let mut right = len - 1;
        while left + 1 < right {
            let mid = (left + right) / 2;
            if condition(&self[mid]) {
                left = mid;
            } else {
                right = mid;
            }
        }

        Some(left)
    }

    fn binary_search_left(&self, condition: F) -> Option<usize> {
        if self.is_empty() {
            return None;
        }

        let len = self.len();

        if condition(&self[0]) {
            return Some(0);
        }
        if !condition(&self[len - 1]) {
            return None;
        }

        let mut left = 0;
        let mut right = len - 1;
        while left + 1 < right {
            let mid = (left + right) / 2;
            if condition(&self[mid]) {
                right = mid;
            } else {
                left = mid;
            }
        }

        Some(right)
    }
}


Measured memory_bytes: 12660