use std::io::*;
use std::sync::Mutex;

pub struct Scanner {
    source: Mutex<Bytes<BufReader<Stdin>>>,
}

impl Scanner {
    pub fn new() -> Scanner {
        Scanner {
            source: Mutex::new(Read::bytes(BufReader::new(stdin()))),
        }
    }
    pub fn source(&mut self) -> &Mutex<Bytes<BufReader<Stdin>>> {
        return &self.source;
    }
}

#[allow(unused_macros)]
macro_rules! rin {
    ( from $scanner:ident, $( $rep:tt )* ) => {
        let mut locked_stdin = $scanner.source().lock().unwrap();
        let mut buf = move || -> String {
            locked_stdin
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        rin_parse!{buf, $($rep)*}
        drop(buf);
    };
}

#[allow(unused_macros)]
macro_rules! rin_parse {
    ( $buf:expr ) => {};
    ( $buf:expr, ) => {};
    ( $buf:expr, $type:tt : $var:tt, $($r:tt)* ) => {
        rin_read!($buf, $type, $var, false);
        rin_parse!($buf, $($r)*);
    };
    ( $buf:expr, mut $type:tt : $var:tt, $($r:tt)* ) => {
        rin_read!($buf, $type, $var, true);
        rin_parse!($buf, $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! rin_read {
    ( $buf:expr, $type:tt, $var:ident, false ) => {
        let $var = read_value!($buf, $type);
    };
    ( $buf:expr, $type:tt, [$($var:ident),*], false ) => {
        $( let $var = read_value!($buf, $type); )*
    };

    ( $buf:expr, $type:tt, $var:ident, true ) => {
        let mut $var = read_value!($buf, $type);
    };
    ( $buf:expr, $type:tt, [$($r:tt)*], true ) => {
        $( let mut $var = read_value!($buf, $type); )*
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ( $next:expr, ( $($t:tt),* ) ) => {
        ( $(read_value!($next, $t)),* )
    };
    ( $next:expr, [ $t:tt ; [$d1:expr, $d2:expr] ] ) => {
        (0..$d1).map(|_| read_value!($next, [$t; $d2])).collect::<Vec<_>>()
    };
    ( $next:expr, [ $t:tt ; $len:expr ] ) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };   
    ( $next:expr, chars ) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ( $next:expr, usize1 ) => {
        read_value!($next, usize) - 1
    };
    ( $next:expr, $t:ty ) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// main function

fn main() {
    let mut sc : Scanner = Scanner::new();
    let t = 1;
    // rin!( from sc, usize : t, );
    for _ in 0..t { solve(&mut sc); }
}

fn solve(sc: &mut Scanner) {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    rin! {
        from sc,
        usize : [n, m],
        mut i64 : k,
        [i64; n] : a,
        [i64; m] : b,
    }

    let mut c = vec![0; n+1];
    let mut d = vec![0; m+1];

    for i in 1..n+1 { c[i] += a[i-1] + c[i-1]; }
    for i in 1..m+1 { d[i] += b[i-1] + d[i-1]; }

    let mut ans = 0;

    let mut idx = m;
    for i in 0..n+1 {
        if c[i] > k { break; }
        while c[i] + d[idx] > k { idx -= 1; }
        ans = std::cmp::max(ans, idx + i);
    }
    
    write!(out, "{}\n", ans).ok();
}

Measured memory_bytes: 8352