#include <bits/stdc++.h>
using namespace std;

    // /* ----------------------------------------

// Data types
#define ll long long
#define db double
#define ull unsigned long long

// Pairs
#define pii pair<int, int>
#define pLL pair<ll, ll>
#define pdd pair<db, db>
#define fi first
#define se second
#define mp make_pair

// Containers
#define pb push_back
#define popb pop_back
#define eb emplace_back
#define pf push_front // ø.deque
#define popf pop_front // ø.deque
#define ef emplace_front // ø.deque
#define vi vector<int> 
#define vs vector<string>
#define vL vector<ll>
#define vc vector<char>
#define vb vector<bool>

// Scanf
#define sci(x) scanf("%d", &x)
#define scii(x, y) scanf("%d %d", &x, &y)
#define scL(x) scanf("%lld", &x)
#define scLL(x, y) scanf("%lld %lld", &x, &y)
#define scs(s) scanf("%s", s)
#define scd(n) scanf("%lf", &n)
#define scld(n) scanf("%llf", &n)

// For loop
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repb(i, n) for (ll i = 1; i <= n; i++)
#define rrep(i, n) for (ll i = n; i >= 0; i--)
#define rrepb(i, n) for (ll i = n; i > 0; i--)

// Searching and Sorting
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define vsort(v) sort(all(v))
#define vsortr(v) sort(rall(v))
#define bs(x, y) binary_search(x.begin(), x.end(), y)
#define cpresent(c, x) ((c).find(x) != (c).end()) // present in container? (returns bool)
#define vpresent(c, x) (find(all(c),x) != (c).end()) // present in vector? (returns bool)

// Math
#define sqr(x) ((x) * (x))
#define cbe(x) ((x) * (x) * (x))
#define lcm(x, y) (x / __gcd(x, y)) * y

// Debug
#define watch(x) cout << (#x) << " is " << (x) << endl

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// -------------------------------------------- */

const double PI = acos(-1.0); 

void solve();

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}

void read_and_write()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
    #endif
}

int main()
{
    read_and_write();
    fastio(); 

    solve(); /* --- test case input ---

    int t; 
    cin >> t;

    int totalTestCases = t;

    while (t--)
    { 
        // cout << "Case #" << totalTestCases - t << ": ";
        solve();
    }
// ------------ */ 

    return 0;
}

void solve()
{
    ll n, m, k;
    cin >> n >> m >> k;
    vL a(n + 1), b(m + 1);
    repb(i, n) cin >> a[i]; 
    repb(i, m) cin >> b[i];
    
    rep(i, n) a[i + 1] += a[i];
    rep(i, m) b[i + 1] += b[i];
    
    ll j = m, ans = 0;
    for(ll i = 0; i <= n; i++)
    {
        if(a[i] > k) break;

        while(a[i] + b[j] > k) j--;
        ans = max(ans, i + j);
    }

    cout << ans << "\n";

    return;
}

Measured memory_bytes: 6344