/* * Solution Template for Tennis Robot II * * Australian Informatics Olympiad 2024 * * This file is provided to assist with reading of input and writing of output * for the problem. You may modify this file however you wish, or * you may choose not to use this file at all. */ #include /* N is the number of bins. */ int N; /* M is the number of instructions. */ int M; /* * X contains the number of balls in each bin. Note that this array starts from * 1 (not 0), and so the values are X[1] to X[N]. */ long long X[200005]; /* * A and B contain the instructions. Note that the arrays start from 0, and so * the instructions are (A[0], B[0]) to (A[M-1], B[M-1]). */ int A[200005]; int B[200005]; long long answer; int main(void) { int i; /* Read the values of N, M, X, A, and B. */ scanf("%d%d", &N, &M); /* Values in X are indexed from 1 to N (not 0 to N-1) */ for (i = 1; i <= N; i++) { scanf("%lld", &X[i]); } for (i = 0; i < M; i++) { scanf("%d", &A[i]); scanf("%d", &B[i]); } /* * 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. */ /* * Please note that the answer may exceed the maximum value * that can be stored in an "int" integer type. * Because of this, you should use the "long long" integer type * instead of "int" when computing your solution. */ /* Write the answer. */ if (answer == -1) { printf("FOREVER\n"); } else { printf("%lld\n", answer); } return 0; }