#include<bits/stdc++.h>
        using namespace std;
        #include <ext/pb_ds/assoc_container.hpp>
        #include <ext/pb_ds/tree_policy.hpp>
        using namespace __gnu_pbds;
        #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
        #define ll long long
        #define int long long
        #define lb long double
        #define f(i,a,b) for(int i=(a);i<=(b);i++)
        #define fd(i,a,b) for(int i=a;i>=b;i--)
        #define vi vector<int>
        #define mii map<int,int>
        #define pii pair<int,int>
        #define si set<int>
        #define pb push_back
        #define mk make_pair
        #define fi first
        #define se second
        #define fv(i,v) for(auto i=v.begin();i!=v.end();++i)
        #define fdv(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
        #define print(a,n) f(i,1,n) cout<<a[i]<<" "; cout<<endl;
        #define printv(v) for(auto iv: v) cout<<iv<<" "; cout<<endl;
        #define all(v) v.begin(),v.end()
        #define r(a,n) ll a[n+1]; f(i,1,n) cin>>a[i];
        #define pi 3.141592653589793238
        const int mod=1e9+7;
        const int inf=1e18;
        int parent[26];
        int size[26];
        const int A=26;
        //bool vis[1000+1]={};
        const int MAXN=1*1e7+1;
        int spf[MAXN];
        int a[MAXN];
        ll power(ll x, unsigned ll y)
        {
            ll res = 1;
            while (y > 0)
            {
                if (y & 1)
                    res = res*x;
                y = y>>1;
                x = x*x;
            }
            return res;
        }

        bool isPrime(int n)
        {
            if (n <= 1)
                return false;
            if (n <= 3)
                return true;

            if (n % 2 == 0 || n % 3 == 0)
                return false;

            for (int i = 5; i * i <= n; i = i + 6)
                if (n % i == 0 || n % (i + 2) == 0)
                    return false;

            return true;
        }
        void sieve()
        {
            spf[1] = 1;
            for (int i=2; i<MAXN; i++)
                spf[i] = i;
            for (int i=4; i<MAXN; i+=2)
                spf[i] = 2;
            for (int i=3; i*i<MAXN; i++)
            {
                if (spf[i] == i)
                {
                    for (int j=i*i; j<MAXN; j+=i)
                        if (spf[j]==j)
                            spf[j] = i;
                }
            }
        }

        int lcm(int a, int b)
        {
            return (a*b)/__gcd(a,b);
        }
        int decToBinary(int n)
        {
            vi v;
            while (n > 0) {
                v.pb(n%2);
                n = n / 2;
            }
            return v.size();
        }
        signed main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            {
                int n,m,k;
                cin>>n>>m>>k;
                r(a,n);
                r(b,m);
                int c[n+1]={0},d[m+1]={0};
                int s1=0,s2=0;
                f(i,1,n)
                {
                    s1+=a[i];c[i]=s1;
                }
                f(i,1,m)
                {
                    s2+=b[i];d[i]=s2;
                }
                int mx=0;
                int j=m;
                f(i,0,n)
                {
                    if(c[i]>k)break;
                    while(d[j]>k-c[i])
                    {
                        j--;
                    }
                    mx=max(mx,i+j);
                }
                cout<<mx<<endl;
            }
        }


Measured memory_bytes: 9884