Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)


ans = 0

for i_n in range(n + 1):
    if a[i_n] > k:
        break

    for j_n in range(m + 1):
        if a[i_n] + b[j_n] <= k:
            # print(i_n, j_n, a[i_n] + b[j_n])
            ans = max(ans, i_n + j_n)

print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)

j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(n, m, k)
# print(a)
# print(b)

ans = set()
ans.add(0)

for i_n in range(0, n+1):
    if a[i_n] > k:
        break

    start_idx = max(list(ans)[-1] - i_n, 0)
    # print('start_idx', start_idx)
    for i_m in range(start_idx, m+1):
        if a[i_n] + b[i_m] > k:
            break

        time_sum = a[i_n] + b[i_m]
        # print(i_n, a[:i_n], i_m, b[:i_m], time_sum, k)
        if time_sum <= k:
            # print(i_n, a[:i_n], i_m, sum(b[:i_m]), k)
            ans.add(i_n + i_m)

# print(ans)

print(list(ans)[-1])


Fixed submission:
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)

j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

# print(n, m, k)
# print(a)
# print(b)

ans = set()
ans.add(0)
time_sum_a = 0
for i_n in range(0, n+1):
    if time_sum_a > k:
        break

    if i_n != 0:
        time_sum_a += a[i_n-1]
    time_sum_b = 0
    for i_m in range(0, m+1):
        if time_sum_a + time_sum_b > k:
            break
        if i_m != 0:
            time_sum_b += b[i_m-1]

        time_sum = time_sum_a + time_sum_b
        # print(i_n, a[:i_n], i_m, b[:i_m], time_sum, k)
        if time_sum <= k:
            # print(i_n, a[:i_n], i_m, sum(b[:i_m]), k)
            ans.add(i_n + i_m)

# print(ans)

print(list(ans)[-1])


Fixed submission:
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)

j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

# print(n, m, k)
# print(a)
# print(b)

ans = set()
ans.add(0)
for i_n in range(0, n+1):
    if sum(a[:i_n]) > k:
        break
    for i_m in range(0, m+1):
        if sum(b[:i_m]) > k:
            break

        time_sum = sum(a[:i_n]) + sum(b[:i_m])
        if time_sum <= k:
            # print(i_n, a[:i_n], i_m, sum(b[:i_m]), k)
            ans.add(i_n + i_m)

# print(ans)

print(list(ans)[-1])


Fixed submission:
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)

j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

print(ans)