///        Saniuzzaman Robin           ///
///        CSE'08, Comilla University  ///

#include<bits/stdc++.h>

/*
#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>
*/


using namespace std;

/*--------------------------Containers------------------------*/
typedef     long long int           ll;
typedef     unsigned long long int  ull;
typedef     vector < int >          vi;
typedef     vector < ll >           vll;
typedef     vector < vi >           vvi;
typedef     pair< int,int >         pi;
typedef     pair< ll, ll >          pll;
typedef     vector< pi >            vpi;
typedef     vector< pll >           vpll;
/*------------------------------------------------------------*/

/*--------------------------Limits & Constants----------------*/
#define     MAX                 200007
#define     MOD                 int(1e9+7)
#define     INF                 ll(8230219982008199610)
#define     MINF                ll(-8230219982008199610)
#define     IL                  INT_MAX
#define     MIL                 INT_MIN
#define     PI                  2*acos(0.0)
/*------------------------------------------------------------*/

/*--------------------------Macros----------------------------*/
#define     fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define     pf                  printf
#define     sc                  scanf
#define     all(a)              (a).begin(),(a).end()
#define     sz(x)               int(x.size())
#define     pb                  push_back
#define     eb                  emplace_back
#define     mp                  make_pair
#define     ff                  first
#define     ss                  second
#define     mem(a,n)            memset(a, n, sizeof(a) )
#define     gcd(a,b)            __gcd(a,b)
#define     lcm(a,b)            (a*(b/gcd(a,b)))
#define     loop0(i,n)          for(int i=0; i<n; i++)
#define     loop1(i,n)          for(int i=1; i<=n; i++)
#define     rev0(i,n)           for(int i=n-1; i>=0; i--)
#define     rev1(i,n)           for(int i=n; i>0; i--)
#define     unik(v)             v.resize(distance(v.begin(),unique(all(v))))
/*------------------------------------------------------------*/

/*----------------------Scans and Prints----------------------*/
#define     sc1(x)              scanf("%d",&x)
#define     sc2(x,y)            scanf("%d %d",&x,&y)
#define     sc3(x,y,z)          scanf("%d %d %d",&x,&y,&z)
#define     scd1(x)             scanf("%lld",&x)
#define     scd2(x,y)           scanf("%lld %lld",&x,&y)
#define     pf1(x)              printf("%d\n",x)
#define     pf2(x,y)            printf("%d %d\n",x,y)
#define     pfd1(x)             printf("%lld\n",x)
#define     pfd2(x,y)           printf("%lld %lld\n",x,y)
#define     t_case(t)           for(int cs = 1; cs<=t; cs++)
#define     print(a,n)          for(int pr = 0; pr<int(n); pr++)cout<<a[pr]<<" ";cout<<endl
#define     printa(x)           cout<<x<<endl;
#define     debug               cout<<" OK "<<endl
/*------------------------------------------------------------*/


/*------------------------Graph Moves-------------------------*/
//const int dx[]= {+1,-1,+0,+0};
//const int dy[]= {+0,+0,+1,-1};
//const int dx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int dy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int dx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int dy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------------------*/


/*------------------------Bitmask-----------------------------*/
//int Set(int N,int pos){return N = (N (1<<pos));}
//int reset(int N,int pos){return N = (N & ~(1<<pos));}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------------------*/


///void Sieve(int n){bool prime[n+1];memset(prime,true,sizeof(prime));for(int p=2; p*p<=n; p++){if(prime[p]==true){for(int i=p*p; i<=n;i+= p)prime[i] = false;}}}
///ll POW(ll a, ll b){ll res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
///ll bigmod(ll a, ll b, ll m){a%=m;ll res=1;while(b>0){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
///ll INV(ll a,ll m){return bigmod(a,m-2,m);}
///int phi[500007];void phi(int N){for(int i=2; i<=N; i++)phi[i] = i;for(int i =2; i<=N; i++){if(phi[i]==i){for(int j=i; j<=N; j+=i)phi[j]-=phi[j]/i;}}}


int main()
{
    fast;

    int n, m, k, x;
    cin>>n>>m>>k;
    vector <ll> a, b;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        if(i)
        {
            a.pb(a[i-1]+x);
        }
        else
            a.pb(x);
    }

    for(int i=0; i<m; i++)
    {
        cin>>x;
        if(i)
        {
            b.pb(b[i-1]+x);
        }
        else
            b.pb(x);
    }
    int ans  = 0;
    for(int i=0; i<n; i++)
    {
        if(k>=a[i])
        {
            int num = k-a[i];
            int cnt = upper_bound(all(b), num) - b.begin();
            ans = max(ans, cnt+i+1);
        }
        else
            break;
    }

    for(int i=0; i<m; i++)
    {
        if(k>=b[i])
        {
            int num = k-b[i];
            int cnt = upper_bound(all(a), num) - a.begin();
            ans = max(ans, cnt+i+1);
        }
        else
            break;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 7956