import std.conv;
import std.string;
import std.algorithm;
import std.array;
import std.stdio;

void main() {
	auto limit = readln.chomp.split(' ').map!(to!long).array[2];
	auto booksA = readln.chomp.split(' ').map!(to!long).array;
	auto booksB = readln.chomp.split(' ').map!(to!long).array;

	long count;
	long time;
	size_t endA = booksA.length;

	foreach (size_t i, e;booksA) {
		if (time + e <= limit) {
			time += e;
			++count;
		} else {
			endA = i;
			break;
		}
	}

	size_t endB = booksB.length;

	foreach (size_t i, e;booksB) {
		if (time + e <= limit) {
			time += e;
			++count;
		} else {
			endB = i;
			break;
		}
	}

	auto answer = count;

	foreach_reverse (i;0..endA) {
		--count;
		time -= booksA[i];

		while (endB < booksB.length && time + booksB[endB] <= limit) {
			time += booksB[endB];
			++endB;
			++count;
		}
		if (count > answer) {
			answer = count;
		}
	}

	answer.writeln;
}
