import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

void main(string[] args)
{
    long n, m, k;
    readf("%d %d %d\n", &n, &m, &k);
    auto as = readln.strip.split(" ").to!(long[]);
    auto bs = readln.strip.split(" ").to!(long[]);

    long ai = 0, bi = 0;
    // aを読めるところまで読む
    long sumt = 0;
    while (ai < n)
    {
        if (sumt + as[ai] > k)
        {
            break;
        }
        sumt += as[ai];
        ai++;
    }

    // aを読むのをやめながらbをよめるところまで読む
    long ans = ai;
    while (true)
    {
        while (bi < m)
        {
            if (sumt + bs[bi] > k)
            {
                break;
            }
            sumt += bs[bi];
            bi++;
        }
        ans = max(ans, ai + bi);
        if (ai == 0)
        {
            break;
        }
        sumt -= as[--ai];
    }
    writeln(ans);

}
