Problem p03651 - Generation 3

Orig Description

Score : 300 points
Problem StatementThere is a box containing N balls. The i-th ball has the integer A_i written on it.
Snuke can perform the following operation any number of times:
Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.
Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
Constraints
1 \leq N \leq 10^5
1 \leq A_i \leq 10^9
1 \leq K \leq 10^9
All input values are integers.
InputInput is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N
OutputIf it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.
Sample Input 13 7
9 3 4
Sample Output 1POSSIBLE
First, take out the two balls 9 and 4, and return them back along with a new ball, abs(9-4)=5.
Next, take out 3 and 5, and return them back along with abs(3-5)=2.
Finally, take out 9 and 2, and return them back along with abs(9-2)=7.
Now we have 7 in the box, and the answer is therefore POSSIBLE.
Sample Input 23 5
6 9 3
Sample Output 2IMPOSSIBLE
No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE.
Sample Input 34 11
11 3 7 15
Sample Output 3POSSIBLE
The box already contains 11 before we do anything. The answer is therefore POSSIBLE.
Sample Input 45 12
10 2 8 6 4
Sample Output 4IMPOSSIBLE

Extracted Specification

An integer N (1 ≤ N ≤ 10^5), representing some quantity or size.
An integer K (1 ≤ K ≤ 10^9), another quantity or size.
A list of integers A of size N, where each integer is between 1 and 10^9.

### Example Input:

```
3
7
9 3 4
```

### Function Signature:
Write a function f(N, K, A) that takes in the input.
```python
def f(N: int, K: int, A: List[int]):
    ''' 
    N: an integer 
    K: an integer 
    A: a list of integers
    '''
```

Test Case Generator

Sure, here is a test case generator for the given problem statement:

```python
import random

def tcgen():
    N = random.randint(1, 10**5)
    A = [random.randint(1, 10**9) for _ in range(N)]
    K = random.randint(1, 10**9)
    return N, K, A

# Example usage
if __name__ == "__main__":
    N, K, A = tcgen()
    print(N, K)
    print(' '.join(map(str, A)))
```

This generator produces random test cases within the constraints given in the problem statement. Here's what each part does:

- `N = random.randint(1, 10**5)`: Generates a random integer `N` between 1 and 100,000, representing the number of balls in the box.
- `A = [random.randint(1, 10**9) for _ in range(N)]`: Creates a list `A` of size `N`, where each element is a random integer between 1 and 1,000,000,000, representing the integers written on the balls.
- `K = random.randint(1, 10**9)`: Generates a random integer `K` between 1 and 1,000,000,000, representing the target integer we want to achieve.

The generated test case is then printed in the required format. Note that this generator does not guarantee whether the output will be "POSSIBLE" or "IMPOSSIBLE", it just creates random valid inputs.

Extract Arguments

def extract_arguments(fh):
    N, K = map(int, fh.readline().strip().split())
    A = list(map(int, fh.readline().strip().split()))
    return N, A, K

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         N, A, K = extract_arguments(fh)
#         f(N, A, K)