#ifdef ONLINE_JUDGE
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")
// #pragma GCC target("f16c")
// #pragma GCC target("fma", "avx2")
// #pragma GCC target("xop", "fma4")
#endif

#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define Deque  std::deque
#define List   std::list
#define Map    std::map
#define Pair   std::pair
#define Queue  std::queue
#define Set    std::set
#define Stack  std::stack
#define String std::string
#define Vector std::vector

typedef long long          ll;
typedef unsigned long long ull;
typedef long double        lf;

#define FILE_INPUT  0
#define FILE_OUTPUT 0

template <class T>
void Read(T* num = NULL) {
  T    x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') { f = -1; }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x  = x * 10 + ch - '0';
    ch = getchar();
  }
  if (num) { *num = x * f; }
  return;
}

template <class T>
void Print(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) { Print(x / 10); }
  putchar(x % 10 + '0');
  return;
}

void FileInputOutput() {
#if FILE_INPUT
  if (freopen("c.in", "r", stdin) == nullptr) { exit(-1); }
#endif
#if FILE_OUTPUT
  if (freopen("c.out", "w", stdout) == nullptr) { exit(-1); }
#endif
  return;
}

template <class T>
T Pow(T a, T b, const T& m) {
  a %= m;
  T res = 1;
  while (b > 0) {
    if (b & 1) { res = res * a % m; }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

template <class T>
T ExGcd(T a, T b, T* x = NULL, T* y = NULL) {
  if (!b) {
    if (x && y) { *y = 0, *x = 1; }
    return a;
  }
  T ans = ExGcd(b, a % b, y, x);
  if (x && y) { *y -= a / b * *x; }
  return ans;
}

const ll N = 3e5 + 5;

ll n, m, k, a[N], b[N], suma[N], sumb[N];

signed main() {
  FileInputOutput();

  Read(&n);
  Read(&m);
  Read(&k);
  for (int i = 1; i <= n; ++i) {
    Read(a + i);
    suma[i] = suma[i - 1] + a[i];
  }
  for (int i = 1; i <= m; ++i) {
    Read(b + i);
    sumb[i] = sumb[i - 1] + b[i];
  }
  if ((a[1] > k) && (b[1] > k)) {
    puts("0");
    exit(0);
  }
  ll maxp = -1;
  for (int i = 1; i <= n; ++i) {
    if (suma[i] > k) { break; }
    auto pos = std::upper_bound(sumb + 1, sumb + m + 1, k - suma[i]) - 1;
    maxp     = std::max<ll>(maxp, i + (pos - sumb));
  }
  for (int i = 1; i <= m; ++i) {
    if (sumb[i] > k) { break; }
    auto pos = std::upper_bound(suma + 1, suma + n + 1, k - sumb[i]) - 1;
    maxp     = std::max<ll>(maxp, i + (pos - suma));
  }
  Print(maxp);
  putchar('\n');
  return 0;
}


Measured memory_bytes: 9860