#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")

using ll = long long int;

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll N, M, K;
ll A[200010], B[200010];
ll a[200010] = {}, b[200010] = {};
ll ans = 0;
ll ai = 0, bi = 0;

int main() {
    cin >> N >> M >> K;
    A[0] = 0;
    a[0] = 0;
    B[0] = 0;
    b[0] = 0;
    REP(i, 1, N + 1 + 1) {
        if (i != N + 1) {
            cin >> A[i];
            a[i] = a[i - 1] + A[i];
        }
        else a[i] = (ll)1e17;
        
        if (a[i] > K && a[i - 1] <= K) {
            ai = i - 1;
        }
    }
    REP(i, 1, M + 1 + 1) {
        if (i != M + 1) {
            cin >> B[i];
            b[i] = b[i - 1] + B[i];
        }
        else b[i] = (ll)1e17;
        
        if (b[i] > K && b[i - 1] <= K) {
            bi = i - 1;
        }
    }
    //a[N + 1] = (ll)1e18;
    //b[M + 1] = (ll)1e18;
    /*
    for (int i = 0; i <= N + 1; i++) {
        cout << "a:" << a[i] << endl;
    }
    for (int i = 0; i <= M + 1; i++) {
        cout << "b:" << b[i] << endl;
    }
    */
    ans = ai;
    ll bii = 0;
    int L = ai + 1;
    bool chk = false;
    //if (A[1] > K && B[1] > K) {
    //    cout << 0 << endl;
    //    return 0;
    //}
    //std::cout << ai << " " << bi << endl;
    //cout << endl;
    for (int i = 0; i < L; i++) {
        //どんどん引いてく
        while (true) {
            //std::cout << ai - i << " " << bii << endl;
            if (K < a[ai - i] + b[0]) break;
            if ((K < a[ai - i] + b[bii] || bii == bi)) {
                if (K < a[ai - i] + b[bii]) bii--;
                if (ai - i + bii > ans) {
                    ans = ai - i + bii;
                    //std::cout << a[ai - i] + b[bii] << endl;
                }
                if (bii == bi) chk = true;
                break;
            }
            else {
                bii++;
                //if (K >= a[ai - i] + b)
            }
        }
        if (chk) break;
    }

    //cout << aii << endl;
    
    //ans = max(ans, bi);
    /*
    ll aii = 0;
    rep(i, M) {
        while (true) {
            if (K < a[aii] + b[bi - i]) {
                aii--;
                if (aii + bi - i > ans) ans = aii + bi - i;
                break;
            }
            else {
                aii++;
            }
        }
    }
    */

    std::cout << ans << endl;

    //rep(i, N + 1) cout << "a" << a[i] << endl;
    //rep(i, M + 1) cout << "b" << b[i] << endl;
    //累積和から計算する
    /*
    bool c = false;
    while(!c) {
        //K回繰り返す
        for (ll j = 0;; j++) {
            if (a[j + ai] < b[j + bi]) {
                if (ans + A[ai] > K) {
                    c = true;
                    break;
                }
                //cout << "A:" << A[ai] << endl;
                ans += A[ai++];
                break;
            }
            else if (a[j + ai] > b[j + bi]) {
                if (ans + B[bi] > K) {
                    c = true;
                    break;
                }
                //cout << "B:" << B[bi] << endl;
                ans += B[bi++];
                break;
            }
            else {

            }
        }
        if (ai + bi == N + M) break;
    }
    cout << ai + bi << endl;
    */

}

/*
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1 1000000000 1000000000 1000000000

5 4 1
1 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
*/

Measured memory_bytes: 9852