import sys sys.setrecursionlimit(1000000000) # # Solution Template for Tennis Robot II # # Australian Informatics Olympiad 2024 # # This file is provided to assist with reading and writing of the input # files for the problem. You may modify this file however you wish, or # you may choose not to use this file at all. # # N is the number of bins. N = 0 # M is the number of instructions. M = 0 # X contains the number of balls in each bin. Note that this list starts from 1 # (not 0), and so the values are X[1] to X[N]. X = [] # A and B contain the instructions. Note that the lists start from 0, and so # the instructions are (A[0], B[0]) to (A[M-1], B[M-1]). A = [] B = [] # Open the input and output files. input_file = open("tennisin.txt", "r") output_file = open("tennisout.txt", "w") # Read the values of N, M, X, A, and B from input file. input_line = input_file.readline().strip() N, M = map(int, input_line.split()) # Values in X are indexed from 1 to N (not 0 to N-1) input_line = input_file.readline().strip() X = [0] + list(map(int, input_line.split())) for i in range(0, M): input_vars = list(map(int, input_file.readline().strip().split())) A.append(input_vars[0]) B.append(input_vars[1]) # TODO: This is where you should compute your solution. Store the number of # instructions that the robot will successfully complete (or -1 if it will run # forever) into the variable answer. answer = 0 # Write the answer to the output file. if answer == -1: output_file.write("FOREVER\n") else: output_file.write("%d\n" % (answer)) # Finally, close the input/output files. input_file.close() output_file.close()