#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define INF (int)1e5+5
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N (int)1e6+2
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;

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

// look for  all edge cases
//search for a pattern



//const int inf = (int)1e16+5;
	
signed main(){
	fast;

	int n,m,k;
	cin >> n >> m >> k;
	vector<int> one(n) ,two(m);
	for(int i =0 ; i < n ; i++){
		cin >>one[i];
	}
	for(int i =0 ; i < m ; i++){
		cin >> two[i];
	}
	
	
	vector<int> pre1(n+1,0);
	vector<int> pre2(m+1,0);
	
	for(int  i = 1; i <= n ;i++){
		pre1[i] = pre1[i-1] + one[i-1];
	}
	for(int i = 1 ; i<= m; i++){
		pre2[i] = pre2[i-1] + two[i-1];  
	}
	
	int ans = 0;
	
	for(int i =1 ; i <= n ;i++){
		int val = k - pre1[i];
		if(val >= 0){
			int books = i;
			ans = max(ans , books);
			
			
			auto it = upper_bound(all(pre2) , val);
			if(it == pre2.end()){
				books += m;
			}
			
			else{
				int pos = ((int)(it - pre2.begin())) -1;
				//debug(val , pos , *it);
				if(pos <= -1)
					pos = 0;
					
				books += pos;
			}
			//debug(books);
			ans = max(ans , books);
		}
	}
	
	for(int i =1 ; i <= m ;i++){
		int val = k - pre2[i];
		if(val >= 0){
			int books = i;
			ans = max(ans , books);
			
			
			auto it = upper_bound(all(pre1) , val)-1;
			if(it == pre1.end()){
				books += n;
			}
			
			else{
				int pos = ((int)(it - pre1.begin())) -1;
				if(pos <= -1)
					pos = 0;
				
				//debug(val , pos , *it);
				books += pos;
			}
			
			ans = max(ans , books);
		}
	}
	
	
	
	cout<<ans;
	

	return 0;
	
}

	



Measured memory_bytes: 9516