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

    AS = [0]
    for i in range(n):
        AS.append(AS[i] + A[i])

    BS = [0]
    for i in range(m):
        BS.append(BS[i] + B[i])

    ans = 0
    for ai in range(n, -1, -1):
        if AS[ai] > k:
            continue

        bi = 0
        while AS[ai] + BS[bi] <= k:
            bi += 1
            if bi == m + 1:
                break

        ans = max(ai + bi - 1, ans)

    print(ans)


if __name__ == '__main__':
    main()


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

    AS = [0]
    for i in range(n):
        AS.append(AS[i] + A[i])

    BS = [0]
    for i in range(m):
        BS.append(BS[i] + B[i])

    ans = 0
    bi = 0
    for ai in range(n, -1, -1):
        if bi == m + 1:
            break

        if AS[ai] > k:
            continue

        while bi < m + 1 and AS[ai] + BS[bi] <= k:
            bi += 1

        ans = max(ai + bi - 1, ans)

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    t = 0
    ca, cb = 0, 0
    for a in A:
        t += a
        if t > k:
            t -= a
            break

        ca += 1

    while True:
        t += B[cb]
        cb += 1

        if t > k:
            cb -= 1
            t -= B[cb]
            break

        if cb == len(B):
            break

    AA = [ca + cb]
    while True:
        if ca == 0 or cb == len(B):
            break

        ca -= 1
        t -= A[ca]
        while True:
            t += B[cb]
            if t > k or cb == len(B):
                break

            cb += 1

        AA.append(ca + cb)

    print(max(AA))


if __name__ == '__main__':
    main()


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

    AS = [0]
    for i in range(n):
        AS.append(AS[i] + A[i])

    BS = [0]
    for i in range(m):
        BS.append(BS[i] + B[i])

    ans = 0
    bi = 0
    for ai in range(n, -1, -1):
        if bi == m + 1:
            break

        if AS[ai] > k:
            continue

        while bi < m + 1 and AS[ai] + BS[bi] <= k:
            bi += 1

        ans = max(ai + bi - 1, ans)

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    t = 0
    ca, cb = 0, 0
    for a in A:
        t += a
        if t > k:
            t -= a
            break

        ca += 1

    while True:
        if t > k:
            cb -= 1
            t -= B[cb]
            break

        if cb == len(B):
            break

        t += B[cb]
        cb += 1

    AA = [ca + cb]
    while True:
        if ca == 0 or cb == len(B):
            break

        ca -= 1
        t -= A[ca]
        while True:
            t += B[cb]
            if t > k or cb == len(B):
                break

            cb += 1

        AA.append(ca + cb)

    print(max(AA))


if __name__ == '__main__':
    main()


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

    AS = [0]
    for i in range(n):
        AS.append(AS[i] + A[i])

    BS = [0]
    for i in range(m):
        BS.append(BS[i] + B[i])

    ans = 0
    bi = 0
    for ai in range(n, -1, -1):
        if bi == m + 1:
            break

        if AS[ai] > k:
            continue

        while bi < m + 1 and AS[ai] + BS[bi] <= k:
            bi += 1

        ans = max(ai + bi - 1, ans)

    print(ans)


if __name__ == '__main__':
    main()