#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n,m,k,p=0,s,ans=0;
  cin>>n>>m>>k;
  int64_t a[n+1],b[m+1];
  a[0]=0,b[0]=0;
  for(int i=1;i<n+1;i++){
    int aa;
    cin>>aa;
    a[i]=a[i-1]+aa;
  }  
  for(int i=1;i<m+1;i++){
  	int bb;
    cin>>bb;
    b[i]=b[i-1]+bb;
  }  
  int t=m;
  while(p<=n&&a[p]<=k){
    for(int i=t;i>=0;i--){
    	if(b[i]+a[p]<=k){
          s=i;
          break;
        }
    }
    t=s;
    ans=max(ans,p+s);
    p++;
  }
  cout<<ans;
}