#include <bits/stdc++.h>
using namespace std;
int n,m,r;
long long a[200002],b[200002],k;
int main()
{ cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin>>n>>m>>k;
  for(int i=1;i<=n;i++)
    cin>>a[i],a[i]=min(k+1,a[i]+a[i-1]);
  for(int i=1;i<=m;i++)
    cin>>b[i],b[i]=min(k+1,b[i]+b[i-1]);
  a[n+1]=b[m+1]=k+1;
  n=m=0;
  long long c=k;
  while(a[n+1]<=c)
    n++;
  r=n;
  while(n>=0)
  { while(a[n]+b[m]<=k)
       r=max(r,n+m),m++;
    n--;
  }
  cout<<r<<'\n';
  return 0;
}
