import 'dart:io';
import 'dart:math';


void main(List<String> arguments) {
  final nmk = stdin.readLineSync().split(' ').map((e) => int.parse(e)).toList();
  final n = nmk[0];
  final m = nmk[1];
  final k = nmk[2];
  final a = stdin.readLineSync().split(' ').map((e) => int.parse(e)).toList();
  final b = stdin.readLineSync().split(' ').map((e) => int.parse(e)).toList();
  final result = _c(n, m, k, a, b);
  print(result);
}

int _c(int n, int m, int k, List<int> A, List<int> B) {
  final a = <int>[0];
  final b = <int>[0];
  for (int i = 0; i < n; i++) {
    a.add(a[i] + A[i]);
  }
  for (int i = 0; i < m; i++) {
    b.add(b[i] + B[i]);
  }
  var ans = 0;
  var j = m;
  for (var i = 0; i < n + 1; i++) {
    if (a[i] > k) {
      break;
    }
    while (b[j] > k - a[i]) {
      j -= 1;
    }
    ans = max(ans, i + j);
  }

  return ans;
}
