Buggy python submission (verdict: Time Limit Exceeded):
def _integral(A):
    result = []
    sum_value = 0
    result.append(sum_value)
    for i in range(len(A)):
        sum_value += A[i]
        result.append(sum_value)
    return result


def _main(N, M, K, A, B):
    integral_a = _integral(A)
    integral_b = _integral(B)
    top_count = 0
    for a_index in range(len(A) + 1)[::-1]:
        a_value = integral_a[a_index]
        if K < a_value:
            continue
        for b_index in range(len(B) + 1)[::-1]:
            if a_value + integral_b[b_index] <= K:
                if top_count < a_index + b_index:
                    top_count = a_index + b_index
                break
    print(top_count)
    #
    #
    # sum_k = 0.0
    # a_index = 0
    # a_len = len(A)
    # b_index = 0
    # b_len = len(B)
    # while sum_k < K:
    #     current_a = A[a_index] if a_index < a_len else None
    #     current_b = B[b_index] if b_index < b_len else None
    #     if current_a is None and current_b is None:
    #         break
    #
    #     if current_a is not None and current_b is None:
    #         if K < sum_k + current_a:
    #             break
    #         sum_k += current_a
    #         a_index += 1
    #     elif current_a is None and current_b is not None:
    #         if K < sum_k + current_b:
    #             break
    #         sum_k += current_b
    #         b_index += 1
    #     elif current_a < current_b:
    #         if K < sum_k + current_a:
    #             break
    #         sum_k += current_a
    #         a_index += 1
    #     else:
    #         if K < sum_k + current_b:
    #             break
    #         sum_k += current_b
    #         b_index += 1
    #
    # print(a_index + b_index)


if __name__ == "__main__":
    Na, Ma, Ka = map(int, input().split())
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)


Fixed submission:
def _integral(A):
    result = []
    sum_value = 0
    result.append(sum_value)
    for i in range(len(A)):
        sum_value += A[i]
        result.append(sum_value)
    return result


def _main(N, M, K, A, B):
    integral_a = _integral(A)
    integral_b = _integral(B)
    top_count = 0
    b_max = len(B)
    for a_index in range(len(A) + 1):
        a_value = integral_a[a_index]
        if K < a_value:
            break
        for b_index in range(0, min(len(B) + 1, b_max + 1))[::-1]:
            if a_value + integral_b[b_index] <= K:
                if top_count < a_index + b_index:
                    top_count = a_index + b_index
                b_max = b_index
                break
    print(top_count)


if __name__ == "__main__":
    Na, Ma, Ka = map(int, input().split())
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)

Buggy python submission (verdict: Time Limit Exceeded):
def _integral(A):
    result = []
    sum_value = 0
    result.append(sum_value)
    for i in range(len(A)):
        sum_value += A[i]
        result.append(sum_value)
    return result


def _main(N, M, K, A, B):
    integral_a = _integral(A)
    integral_b = _integral(B)
    top_count = 0
    for a_index in range(len(A) + 1):
        a_value = integral_a[a_index]
        for b_index in range(len(B) + 1):
            if a_value + integral_b[b_index] <= K:
                if top_count < a_index + b_index:
                    top_count = a_index + b_index
    print(top_count)
    #
    #
    # sum_k = 0.0
    # a_index = 0
    # a_len = len(A)
    # b_index = 0
    # b_len = len(B)
    # while sum_k < K:
    #     current_a = A[a_index] if a_index < a_len else None
    #     current_b = B[b_index] if b_index < b_len else None
    #     if current_a is None and current_b is None:
    #         break
    #
    #     if current_a is not None and current_b is None:
    #         if K < sum_k + current_a:
    #             break
    #         sum_k += current_a
    #         a_index += 1
    #     elif current_a is None and current_b is not None:
    #         if K < sum_k + current_b:
    #             break
    #         sum_k += current_b
    #         b_index += 1
    #     elif current_a < current_b:
    #         if K < sum_k + current_a:
    #             break
    #         sum_k += current_a
    #         a_index += 1
    #     else:
    #         if K < sum_k + current_b:
    #             break
    #         sum_k += current_b
    #         b_index += 1
    #
    # print(a_index + b_index)


if __name__ == "__main__":
    Na, Ma, Ka = map(int, input().split())
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)


Fixed submission:
def _integral(A):
    result = []
    sum_value = 0
    result.append(sum_value)
    for i in range(len(A)):
        sum_value += A[i]
        result.append(sum_value)
    return result


def _main(N, M, K, A, B):
    integral_a = _integral(A)
    integral_b = _integral(B)
    top_count = 0
    b_max = len(B)
    for a_index in range(len(A) + 1):
        a_value = integral_a[a_index]
        if K < a_value:
            break
        for b_index in range(0, min(len(B) + 1, b_max + 1))[::-1]:
            if a_value + integral_b[b_index] <= K:
                if top_count < a_index + b_index:
                    top_count = a_index + b_index
                b_max = b_index
                break
    print(top_count)


if __name__ == "__main__":
    Na, Ma, Ka = map(int, input().split())
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)