#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc, a, b, m;
    cin >> n >> m >> k;
    vector<LL> v1(n), v2(m), sum1(n), sum2(m);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
    }
    for (i = 0; i < m; i++)
    {
        cin >> v2[i];
    }
    LL prev = 0;
    for (i = 0; i < n; i++)
    {
        sum1[i] = v1[i] + prev;
        prev = sum1[i];
    }
    prev = 0;
    for (i = 0; i < m; i++)
    {
        sum2[i] = v2[i] + prev;
        prev = sum2[i];
    }
    LL maxima = 0;
    for (i = 0; i < n; i++)
    {
        // debug(i);
        LL pos1 = i;
        LL b1 = pos1 + 1;
        if (sum1[i] <= k)
        {
            LL lb = 0, ub = m - 1, mid;
            LL pos = m;
            LL rem = k - sum1[i];
            LL b2 = -1;
            pos = -1;
            //debug(rem);
            if (rem >= sum2[m - 1])
            {
                // debug(m);
                // debug(sum2[m-1]);
                b2 = m;
            }
            else if (rem < sum2[0])
            {
                //cout<<"b2 is 0"<<endl;
                b2 = 0;
            }
            else
            {
                while (lb <= ub)
                {
                    mid = (lb + ub) / 2;
                    if (sum2[mid] <= rem)
                    {
                        pos = mid;
                        lb = mid + 1;
                    }
                    else
                    {
                        ub = mid - 1;
                    }
                }
                b2 = pos + 1;
            }
            //debug(b2);

            maxima = max(maxima, b1 + b2);
        }
        else
        {
            break;
        }
        // part;
    }

    if (true)
    {
        LL lb = 0, ub = m - 1, mid;
        LL pos = m;
        LL rem = k ;
        LL b2 = -1;
        pos = -1;
        LL b1=0;
        //debug(rem);
        if (rem >= sum2[m - 1])
        {
            // debug(m);
            // debug(sum2[m-1]);
            b2 = m;
        }
        else if (rem < sum2[0])
        {
            //cout<<"b2 is 0"<<endl;
            b2 = 0;
        }
        else
        {
            while (lb <= ub)
            {
                mid = (lb + ub) / 2;
                if (sum2[mid] <= rem)
                {
                    pos = mid;
                    lb = mid + 1;
                }
                else
                {
                    ub = mid - 1;
                }
            }
            b2 = pos + 1;
        }
        //debug(b2);

        maxima = max(maxima, b1 + b2);
    }

    cout << maxima << endl;

    return 0;
}


Measured memory_bytes: 9528