Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N , M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    book = 0

    for i in range(N+1) :
        re = M
        if al[i] > K :
            break
        for j in range(M+1) :
            if bl[re] <= K - al[i] :
                break
            else :
                re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N , M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    book = 0
    re = M

    for i in range(N+1) :
        if al[i] > K :
            break
        #for j in range(M+1) :
        #    if bl[re] <= K - al[i] :
        #        break
        #    else :
        #        re -= 1
        while bl[re] > K - al[i] :
            re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N , M, K = map(int, input().split())
    A_list = [A for A in input().split()]
    B_list = [B for B in input().split()]
    A_list = list(map(int, A_list))
    B_list = list(map(int, B_list))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    re = M
    book = 0

    for i in range(N+1) :
        re = M
        if al[i] > K :
            break
        for j in range(M+1) :
            if bl[re] <= K - al[i] :
                break
            else :
                re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N , M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    book = 0
    re = M

    for i in range(N+1) :
        if al[i] > K :
            break
        #for j in range(M+1) :
        #    if bl[re] <= K - al[i] :
        #        break
        #    else :
        #        re -= 1
        while bl[re] > K - al[i] :
            re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N , M, K = map(int, input().split())
    A_list = [A for A in input().split()]
    B_list = [B for B in input().split()]
    A_list = list(map(int, A_list))
    B_list = list(map(int, B_list))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    re = M
    ans = 0
    book = []

    for i in range(N+1) :
        re = M
        if al[i] > K :
            continue
        for j in range(M+1) :
            ans = al[i] + bl[re]
            #print(ans)
            re -= 1
            if ans <= K :
                book.append(i + re + 1)
                break

    print(max(book))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N , M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    book = 0
    re = M

    for i in range(N+1) :
        if al[i] > K :
            break
        #for j in range(M+1) :
        #    if bl[re] <= K - al[i] :
        #        break
        #    else :
        #        re -= 1
        while bl[re] > K - al[i] :
            re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()